private void disChargeAnimation() {
MyImageView = (ImageView) findViewById(R.id.myImageView);
MyImageView.clearAnimation();
MyImageView.setBackgroundResource(R.drawable.arrow_animation);
dischargeAnim = (AnimationDrawable) MyImageView.getBackground();
dischargeAnim.start();
}
private void chargeAnimation() {
MyImageView = (ImageView) findViewById(R.id.myImageView);
MyImageView.clearAnimation();
MyImageView.setBackgroundResource(R.drawable.arrow_back_animation);
chargeAnim = (AnimationDrawable) MyImageView.getBackground();
chargeAnim.start();
}
Logcat跟踪
08-22 18:01:04.840: I/Process(434): Sending signal. PID: 434 SIG: 9
08-22 18:16:20.500: W/ResourceType(471): No package identifier when getting value for resource number 0x00000000
08-22 18:16:21.460: D/dalvikvm(471): GC_EXTERNAL_ALLOC freed 253K, 51% free 2780K/5639K, external 1764K/2137K, paused 43ms
08-22 18:16:21.619: D/dalvikvm(471): GC_EXTERNAL_ALLOC freed 28K, 52% free 2752K/5639K, external 3366K/4203K, paused 44ms
08-22 18:16:21.869: D/dalvikvm(471): GC_EXTERNAL_ALLOC freed 1K, 52% free 2753K/5639K, external 5167K/5167K, paused 42ms
08-22 18:16:22.159: D/dalvikvm(471): GC_EXTERNAL_ALLOC freed 16K, 52% free 2757K/5639K, external 6968K/6968K, paused 48ms
08-22 18:16:22.410: D/dalvikvm(471): GC_EXTERNAL_ALLOC freed 6K, 52% free 2761K/5639K, external 8770K/8952K, paused 38ms
08-22 18:16:22.759: D/dalvikvm(471): GC_EXTERNAL_ALLOC freed 9K, 51% free 2766K/5639K, external 10571K/11018K, paused 43ms
08-22 18:16:23.109: D/dalvikvm(471): GC_EXTERNAL_ALLOC freed 15K, 51% free 2769K/5639K, external 12373K/12819K, paused 50ms
08-22 18:16:23.549: D/dalvikvm(471): GC_EXTERNAL_ALLOC freed 1K, 51% free 2769K/5639K, external 14174K/14621K, paused 44ms
08-22 18:16:23.839: D/dalvikvm(471): GC_EXTERNAL_ALLOC freed 1K, 51% free 2771K/5639K, external 15976K/16422K, paused 39ms
08-22 18:16:24.139: D/dalvikvm(471): GC_EXTERNAL_ALLOC freed 1K, 51% free 2771K/5639K, external 17777K/18224K, paused 47ms
08-22 18:16:24.169: E/dalvikvm-heap(471): 1844640-byte external allocation too large for this process.
08-22 18:16:24.209: I/dalvikvm-heap(471): Clamp target GC heap from 24.610MB to 24.000MB
08-22 18:16:24.209: E/GraphicsJNI(471): VM won't let us allocate 1844640 bytes
08-22 18:16:24.209: D/dalvikvm(471): GC_FOR_MALLOC freed <1K, 51% free 2771K/5639K, external 17777K/18224K, paused 29ms
08-22 18:16:24.223: D/AndroidRuntime(471): Shutting down VM
08-22 18:16:24.223: W/dalvikvm(471): threadid=1: thread exiting with uncaught exception (group=0x40015560)
08-22 18:16:24.239: E/AndroidRuntime(471): FATAL EXCEPTION: main
08-22 18:16:24.239: E/AndroidRuntime(471): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
08-22 18:16:24.239: E/AndroidRuntime(471): at android.graphics.Bitmap.nativeCreate(Native Method)
08-22 18:16:24.239: E/AndroidRuntime(471): at android.graphics.Bitmap.createBitmap(Bitmap.java:477)
08-22 18:16:24.239: E/AndroidRuntime(471): at android.graphics.Bitmap.createBitmap(Bitmap.java:444)
08-22 18:16:24.239: E/AndroidRuntime(471): at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:349)
08-22 18:16:24.239: E/AndroidRuntime(471): at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:498)
08-22 18:16:24.239: E/AndroidRuntime(471): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:473)
08-22 18:16:24.239: E/AndroidRuntime(471): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:336)
08-22 18:16:24.239: E/AndroidRuntime(471): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
08-22 18:16:24.239: E/AndroidRuntime(471): at android.content.res.Resources.loadDrawable(Resources.java:1709)
08-22 18:16:24.239: E/AndroidRuntime(471): at android.content.res.Resources.getDrawable(Resources.java:581)
08-22 18:16:24.239: E/AndroidRuntime(471): at android.graphics.drawable.AnimationDrawable.inflate(AnimationDrawable.java:267)
08-22 18:16:24.239: E/AndroidRuntime(471): at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:787)
08-22 18:16:24.239: E/AndroidRuntime(471): at android.graphics.drawable.Drawable.createFromXml(Drawable.java:728)
08-22 18:16:24.239: E/AndroidRuntime(471): at android.content.res.Resources.loadDrawable(Resources.java:1694)
08-22 18:16:24.239: E/AndroidRuntime(471): at android.content.res.Resources.getDrawable(Resources.java:581)
08-22 18:16:24.239: E/AndroidRuntime(471): at android.view.View.setBackgroundResource(View.java:7533)
08-22 18:16:24.239: E/AndroidRuntime(471): at com.water.charger.MainView.chargeAnimation(MainView.java:186)
08-22 18:16:24.239: E/AndroidRuntime(471): at com.water.charger.MainView.onCreate(MainView.java:88)
08-22 18:16:24.239: E/AndroidRuntime(471): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-22 18:16:24.239: E/AndroidRuntime(471): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
08-22 18:16:24.239: E/AndroidRuntime(471): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
08-22 18:16:24.239: E/AndroidRuntime(471): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
08-22 18:16:24.239: E/AndroidRuntime(471): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
08-22 18:16:24.239: E/AndroidRuntime(471): at android.os.Handler.dispatchMessage(Handler.java:99)
08-22 18:16:24.239: E/AndroidRuntime(471): at android.os.Looper.loop(Looper.java:123)
08-22 18:16:24.239: E/AndroidRuntime(471): at android.app.ActivityThread.main(ActivityThread.java:3683)
08-22 18:16:24.239: E/AndroidRuntime(471): at java.lang.reflect.Method.invokeNative(Native Method)
08-22 18:16:24.239: E/AndroidRuntime(471): at java.lang.reflect.Method.invoke(Method.java:507)
08-22 18:16:24.239: E/AndroidRuntime(471): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-22 18:16:24.239: E/AndroidRuntime(471): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-22 18:16:24.239: E/AndroidRuntime(471): at dalvik.system.NativeStart.main(Native Method)
08-22 18:18:27.889: I/Process(471): Sending signal. PID: 471 SIG: 9
08-22 18:25:12.329: D/dalvikvm(488): GC_EXTERNAL_ALLOC freed 253K, 51% free 2779K/5639K, external 1764K/2137K, paused 44ms
08-22 18:25:12.519: D/dalvikvm(488): GC_EXTERNAL_ALLOC freed 39K, 52% free 2753K/5639K, external 3366K/4203K, paused 51ms
08-22 18:25:12.779: D/dalvikvm(488): GC_EXTERNAL_ALLOC freed 2K, 52% free 2755K/5639K, external 5167K/5167K, paused 37ms
08-22 18:25:13.049: D/dalvikvm(488): GC_EXTERNAL_ALLOC freed 11K, 52% free 2759K/5639K, external 6968K/6968K, paused 45ms
08-22 18:25:13.299: D/dalvikvm(488): GC_EXTERNAL_ALLOC freed 11K, 51% free 2765K/5639K, external 8770K/8952K, paused 38ms
08-22 18:25:13.609: D/dalvikvm(488): GC_EXTERNAL_ALLOC freed <1K, 51% free 2766K/5639K, external 10571K/11018K, paused 66ms
08-22 18:25:13.849: D/dalvikvm(488): GC_EXTERNAL_ALLOC freed <1K, 51% free 2767K/5639K, external 12373K/12819K, paused 38ms
08-22 18:25:14.110: D/dalvikvm(488): GC_EXTERNAL_ALLOC freed 13K, 51% free 2771K/5639K, external 14174K/14621K, paused 46ms
08-22 18:25:14.359: D/dalvikvm(488): GC_EXTERNAL_ALLOC freed <1K, 51% free 2771K/5639K, external 15976K/16422K, paused 37ms
08-22 18:25:14.609: D/dalvikvm(488): GC_EXTERNAL_ALLOC freed 1K, 51% free 2771K/5639K, external 17777K/18224K, paused 46ms
08-22 18:25:14.640: E/dalvikvm-heap(488): 1844640-byte external allocation too large for this process.
08-22 18:25:14.709: I/dalvikvm-heap(488): Clamp target GC heap from 24.611MB to 24.000MB
08-22 18:25:14.709: E/GraphicsJNI(488): VM won't let us allocate 1844640 bytes
08-22 18:25:14.709: D/dalvikvm(488): GC_FOR_MALLOC freed <1K, 51% free 2771K/5639K, external 17777K/18224K, paused 34ms
08-22 18:25:14.719: D/AndroidRuntime(488): Shutting down VM
08-22 18:25:14.719: W/dalvikvm(488): threadid=1: thread exiting with uncaught exception (group=0x40015560)
08-22 18:25:14.729: E/AndroidRuntime(488): FATAL EXCEPTION: main
08-22 18:25:14.729: E/AndroidRuntime(488): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
08-22 18:25:14.729: E/AndroidRuntime(488): at android.graphics.Bitmap.nativeCreate(Native Method)
08-22 18:25:14.729: E/AndroidRuntime(488): at android.graphics.Bitmap.createBitmap(Bitmap.java:477)
08-22 18:25:14.729: E/AndroidRuntime(488): at android.graphics.Bitmap.createBitmap(Bitmap.java:444)
08-22 18:25:14.729: E/AndroidRuntime(488): at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:349)
08-22 18:25:14.729: E/AndroidRuntime(488): at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:498)
08-22 18:25:14.729: E/AndroidRuntime(488): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:473)
08-22 18:25:14.729: E/AndroidRuntime(488): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:336)
08-22 18:25:14.729: E/AndroidRuntime(488): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
08-22 18:25:14.729: E/AndroidRuntime(488): at android.content.res.Resources.loadDrawable(Resources.java:1709)
08-22 18:25:14.729: E/AndroidRuntime(488): at android.content.res.Resources.getDrawable(Resources.java:581)
08-22 18:25:14.729: E/AndroidRuntime(488): at android.graphics.drawable.AnimationDrawable.inflate(AnimationDrawable.java:267)
08-22 18:25:14.729: E/AndroidRuntime(488): at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:787)
08-22 18:25:14.729: E/AndroidRuntime(488): at android.graphics.drawable.Drawable.createFromXml(Drawable.java:728)
08-22 18:25:14.729: E/AndroidRuntime(488): at android.content.res.Resources.loadDrawable(Resources.java:1694)
08-22 18:25:14.729: E/AndroidRuntime(488): at android.content.res.Resources.getDrawable(Resources.java:581)
08-22 18:25:14.729: E/AndroidRuntime(488): at android.view.View.setBackgroundResource(View.java:7533)
08-22 18:25:14.729: E/AndroidRuntime(488): at com.water.charger.MainView.chargeAnimation(MainView.java:186)
08-22 18:25:14.729: E/AndroidRuntime(488): at com.water.charger.MainView.onCreate(MainView.java:88)
08-22 18:25:14.729: E/AndroidRuntime(488): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-22 18:25:14.729: E/AndroidRuntime(488): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
08-22 18:25:14.729: E/AndroidRuntime(488): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
08-22 18:25:14.729: E/AndroidRuntime(488): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
08-22 18:25:14.729: E/AndroidRuntime(488): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
08-22 18:25:14.729: E/AndroidRuntime(488): at android.os.Handler.dispatchMessage(Handler.java:99)
08-22 18:25:14.729: E/AndroidRuntime(488): at android.os.Looper.loop(Looper.java:123)
08-22 18:25:14.729: E/AndroidRuntime(488): at android.app.ActivityThread.main(ActivityThread.java:3683)
08-22 18:25:14.729: E/AndroidRuntime(488): at java.lang.reflect.Method.invokeNative(Native Method)
08-22 18:25:14.729: E/AndroidRuntime(488): at java.lang.reflect.Method.invoke(Method.java:507)
08-22 18:25:14.729: E/AndroidRuntime(488): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-22 18:25:14.729: E/AndroidRuntime(488): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-22 18:25:14.729: E/AndroidRuntime(488): at dalvik.system.NativeStart.main(Native Method)
08-22 18:25:18.049: I/Process(488): Sending signal. PID: 488 SIG: 9
答案 0 :(得分:0)
您的资源R.drawable.arrow_back_animation
看起来太大,无法加载Android并且正在抛出java.lang.OutOfMemoryError: bitmap size exceeds VM budget
。
我猜这是一个长动画/非常大的图像。
检查图像的大小/尝试压缩并避免使用大图像。根据经验,Android上的最大堆大小通常为20-30mb。您不应该在接近此限制的任何地方加载图像。
答案 1 :(得分:0)
看来你有内存泄漏问题。完成setCallBack(null)
对象后,尝试通过调用AnimationDrawable
来释放资源。