0
我正在开发一种应用程序,使用一种本地背景。这个想法是使这个变化。我设法使用此代码更改“背景”。无法删除可绘制的虚拟机预算崩溃
Bitmap bMap = BitmapFactory.decodeFile(sharedPreferences.getString("PICTURE", ""));
Drawable d =new BitmapDrawable(bMap);
bac.setBackgroundDrawable(d);
}
问题是,每当我返回到“背景屏幕”,应用程序崩溃,因为OutOfMemoryError。然后它显示新的背景。我需要一些使应用程序不会崩溃的代码。我在ImageView中管理这个,但不在LinearLayout中。对于ImageView的我用这个代码:
Bitmap bMap = BitmapFactory.decodeFile(sharedPreferences.getString("PICTURE", ""));
image.setImageBitmap(bMap);
,并避免其崩溃:
@Override
protected void onPause() {
super.onPause();
unbindDrawables(findViewById(R.id.iv_pic));
System.gc();
}
private void unbindDrawables(View view) {
if (view.getBackground() != null) {
view.getBackground().setCallback(null);
}
if (view instanceof ViewGroup) {
for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
unbindDrawables(((ViewGroup) view).getChildAt(i));
}
((ViewGroup) view).removeAllViews();
}
}
@Override
protected void onDestroy() {
super.onDestroy();
unbindDrawables(findViewById(R.id.iv_pic));
System.gc();
}
我如何做同样的LinearLayout中?