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>