0

I'm currently building an app but keep having memory issues. Our start screen, which only has a background and a button uses 160 MB ram usually. This must be way too much for what it is doing.

This trend continues throughout my app.

I have included the XML and java code. I also looked at the allocation of the memory. Almost all of the memory is occupied by three things. Three dispatches to be precise. I have no clue what this means.

package com.example.tonymurchison.illuminandus;

import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.widget.ImageView;


public class MainActivity extends AppCompatActivity {

private ImageView startButton;
private ImageView fadeView;

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    getSupportActionBar().hide();


    startButton = (ImageView) findViewById(R.id.start_button);

}

public void startButtonClick(View v){
    //TODO create animation
    Intent intent = new Intent(MainActivity.this,LevelSelect.class);
    startActivity(intent);
    finish();

}

private void animateIn(ImageView image) {
    Animation fadein = new AlphaAnimation(0.f, 1.f);
    fadein.setDuration(500);
    final View viewToAnimate = image;
    fadein.setAnimationListener(new Animation.AnimationListener(){

        @Override
        public void onAnimationStart(Animation animation){}

        @Override
        public void onAnimationRepeat(Animation animation){}

        @Override
        public void onAnimationEnd(Animation animation){
            Intent intent = new Intent(MainActivity.this,LevelSelect.class);
            startActivity(intent);
        }
    });
    image.startAnimation(fadein);
}

}

xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="0dp"
    android:paddingLeft="0dp"
    android:paddingRight="0dp"
    android:paddingTop="0dp"
    tools:context="com.example.tonymurchison.illuminandus.MainActivity"
    android:background="@drawable/titlescreen_background">

    <ImageView
        android:layout_width="300dp"
        android:layout_height="wrap_content"
        android:id="@+id/start_button"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:src="@drawable/start_button"
        android:onClick="startButtonClick"/>


</RelativeLayout>
  • One lists a lot of java.nio.ByteArrayBuffer things. The second a lot of org.apache.harmony.dalvik.ddmc.Chunk things. And the third a lot of java.lang.Integer things. – sateeprikker Mar 21 '16 at 20:53
  • whats the physical size of `@drawable/titlescreen_background` and `@drawable/start_button` – Gueorgui Obregon Mar 21 '16 at 21:05
  • 1.14MB and 33kb respectively – sateeprikker Mar 21 '16 at 21:09
  • Possible duplicate of [High resolution Image - OutOfMemoryError](http://stackoverflow.com/questions/18385362/high-resolution-image-outofmemoryerror) – Gueorgui Obregon Mar 21 '16 at 21:16
  • `titlescreen_background` is to **BIG**. Reduce image size or try this http://stackoverflow.com/a/18385448/4848308. I suggest you the first one. – Gueorgui Obregon Mar 21 '16 at 21:18
  • I have tried reducing the size of the image, but that wouldn't become smaller and I still would like to have a high resolution background. I also tried the bitmap technique. This doubled my ram usage to 305MB... Or I might be doing something wrong. – sateeprikker Mar 21 '16 at 21:47

0 Answers0