I have animation drawable of a cat jumping(it consists of 5 separate images being loaded), here is xml for the animation:
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/cat_page_4_animation" android:oneshot="true">
<item android:drawable="@drawable/page_4_kitten_jumping1" android:duration="250" />
<item android:drawable="@drawable/page_4_kitten_jumping2" android:duration="250" />
<item android:drawable="@drawable/page_4_kitten_jumping3" android:duration="250" />
<item android:drawable="@drawable/page_4_kitten_jumping4" android:duration="250" />
<item android:drawable="@drawable/page_4_kitten_jumping5" android:duration="250" />
<item android:drawable="@drawable/page_4_kitten_jumping1" android:duration="250" />
I suspect the animation is the problem - it has too many images, the first time i launch the activity it crashes, i press OK, it does launch!
The error i see on the first crash is this:
process: nis.animation_door, PID: 24446
java.lang.OutOfMemoryError
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:594)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:429)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:856)
at android.content.res.Resources.loadDrawable(Resources.java:2129)
at android.content.res.Resources.getDrawable(Resources.java:708)
at android.graphics.drawable.AnimationDrawable.inflate(AnimationDrawable.java:282)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:963)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:893)
at android.content.res.Resources.loadDrawable(Resources.java:2111)
at android.content.res.Resources.getDrawable(Resources.java:708)
at android.view.View.setBackgroundResource(View.java:15451)
at nis.animation_door.Page5.onCreate(Page5.java:31)
Code:
protected void onCreate(Bundle savedInstanceState) {
Toast.makeText(Page5.this, " page 5 onCreate", Toast.LENGTH_SHORT).show();
super.onCreate(savedInstanceState);
setContentView(R.layout.page5);
forward = (ImageView)findViewById(R.id.to_page_6);
backward = (ImageView)findViewById(R.id.to_page_4);
cat_jump = (ImageView)findViewById(R.id.cat_jump);
cat_jump.setBackgroundResource(R.drawable.page_5_cat_jumping);
final AnimationDrawable frameAnimation = (AnimationDrawable) cat_jump.getBackground();
cat_jump.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
frameAnimation.start();
}
});
The actual line where it crashes is cat.setBackgroundResource(). But why does it launch after a crash?