我的应用程序中有高分辨率图像。我正在缩放并将其设置为onResume()中片段的背景并将其循环onPause()。
@Override
public void onResume() {
if(obj_bitmap == null)
{
obj_bitmap = ImageUtility.decodeResourceBitmapImage(getResources(), R.drawable.background, int_display_width, int_display_height);
Drawable obj_drawable = new BitmapDrawable(getResources(), obj_bitmap);
linearlayout_event_list_parent.setBackground(obj_drawable);
}
autocompletetextview_search.clearFocus();
super.onResume();
}
/* (non-Javadoc)
* @see android.support.v4.app.Fragment#onPause()
*/
@Override
public void onPause() {
if(obj_bitmap != null && !obj_bitmap.isRecycled())
{
obj_bitmap.recycle();
obj_bitmap = null;
System.gc();
}
super.onPause();
}
obj_bitmap是我的位图对象。图像分辨率为1440X2582。 错误:
> 04-15 11:56:58.381: E/AndroidRuntime(19833): FATAL EXCEPTION: main
04-15 11:56:58.381: E/AndroidRuntime(19833): Process: com.eventizon, PID: 19833
04-15 11:56:58.381: E/AndroidRuntime(19833): java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap@64da1d00
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.graphics.Canvas.throwIfCannotDraw(Canvas.java:1084)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.view.GLES20Canvas.drawBitmap(GLES20Canvas.java:844)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:490)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.view.View.draw(View.java:14493)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.view.View.getDisplayList(View.java:13405)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.view.View.getDisplayList(View.java:13447)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.view.View.draw(View.java:14225)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.view.ViewGroup.drawChild(ViewGroup.java:3105)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2942)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.view.View.getDisplayList(View.java:13400)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.view.View.getDisplayList(View.java:13447)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.view.View.draw(View.java:14225)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.view.ViewGroup.drawChild(ViewGroup.java:3105)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2942)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.view.View.getDisplayList(View.java:13400)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.view.View.getDisplayList(View.java:13447)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.view.View.draw(View.java:14225)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.view.ViewGroup.drawChild(ViewGroup.java:3105)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.support.v4.widget.DrawerLayout.drawChild(DrawerLayout.java:1086)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2942)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.view.View.getDisplayList(View.java:13400)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.view.View.getDisplayList(View.java:13447)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.view.View.draw(View.java:14225)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.view.ViewGroup.drawChild(ViewGroup.java:3105)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2942)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.view.View.draw(View.java:14511)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.widget.FrameLayout.draw(FrameLayout.java:472)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.view.View.getDisplayList(View.java:13405)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.view.View.getDisplayList(View.java:13447)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.view.View.draw(View.java:14225)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.view.ViewGroup.drawChild(ViewGroup.java:3105)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2942)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.view.View.getDisplayList(View.java:13400)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.view.View.getDisplayList(View.java:13447)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.view.View.draw(View.java:14225)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.view.ViewGroup.drawChild(ViewGroup.java:3105)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2942)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.view.View.getDisplayList(View.java:13400)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.view.View.getDisplayList(View.java:13447)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.view.View.draw(View.java:14225)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.view.ViewGroup.drawChild(ViewGroup.java:3105)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2942)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.view.View.getDisplayList(View.java:13400)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.view.View.getDisplayList(View.java:13447)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.view.View.draw(View.java:14225)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.view.ViewGroup.drawChild(ViewGroup.java:3105)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2942)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.view.View.draw(View.java:14511)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.widget.FrameLayout.draw(FrameLayout.java:472)
04-15 11:56:58.381: E/AndroidRuntime(19833): at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2326)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.view.View.getDisplayList(View.java:13405)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.view.View.getDisplayList(View.java:13447)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.view.HardwareRenderer$GlRenderer.buildDisplayList(HardwareRenderer.java:1577)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.view.HardwareRenderer$GlRenderer.draw(HardwareRenderer.java:1449)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.view.ViewRootImpl.draw(ViewRootImpl.java:2407)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2279)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1909)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1019)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5725)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.view.Choreographer.doCallbacks(Choreographer.java:574)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.view.Choreographer.doFrame(Choreographer.java:544)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.os.Handler.handleCallback(Handler.java:733)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.os.Handler.dispatchMessage(Handler.java:95)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.os.Looper.loop(Looper.java:136)
04-15 11:56:58.381: E/AndroidRuntime(19833): at android.app.ActivityThread.main(ActivityThread.java:50
答案 0 :(得分:2)
当应用程序进入“onPause”时,此时可能仍会显示,因此回收仍然使用的位图会使其崩溃。如果你真的想在那里做,那就先清除背景,这样它就不再使用那个位图了。