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中?