public class BitmapDataFragment extends Fragment {
public static final String TAG = "bitmapsaver";
private Bitmap bitmap;
private BitmapDataFragment(Bitmap bitmap) {
this.bitmap = bitmap;
}
public static BitmapDataFragment newInstance(Bitmap bitmap) {
return new BitmapDataFragment(bitmap);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRetainInstance(true);
}
public Bitmap getData() {
return bitmap;
}
}
@Override
protected void onSaveInstanceState(Bundle outState) {
if (mBitmap != null) {
getSupportFragmentManager().beginTransaction()
.add(BitmapDataFragment.newInstance(mBitmap), BitmapDataFragment.TAG)
.commit();
outState.putBoolean(SENSE_IMAGE_KEY, true);
} else {
outState.putBoolean(SENSE_IMAGE_KEY, false);
}
super.onSaveInstanceState(outState);
}
if (savedInstanceState.getBoolean(SENSE_IMAGE_KEY)) {
BitmapDataFragment fragment = (BitmapDataFragment) getSupportFragmentManager()
.findFragmentByTag(BitmapDataFragment.TAG);
bitmap = fragment.getData();
getSupportFragmentManager().beginTransaction().remove(fragment).commit();
}
if (!f.mRetaining) {
f.performDestroy();
}
f.mCalled = false;
f.onDetach();
if (!f.mCalled) {
throw new SuperNotCalledException("Fragment " + f
+ " did not call through to super.onDetach()");
}
if (!keepActive) {
if (!f.mRetaining) {
makeInactive(f);
} else {
f.mActivity = null;
f.mParentFragment = null;
f.mFragmentManager = null;
}
}
/**
* Control whether a fragment instance is retained across Activity
* re-creation (such as from a configuration change). This can only
* be used with fragments not in the back stack. If set, the fragment
* lifecycle will be slightly different when an activity is recreated:
* <ul>
* <li> {@link #onDestroy()} will not be called (but {@link #onDetach()} still
* will be, because the fragment is being detached from its current activity).
* <li> {@link #onCreate(Bundle)} will not be called since the fragment
* is not being re-created.
* <li> {@link #onAttach(Activity)} and {@link #onActivityCreated(Bundle)} <b>will</b>
* still be called.
* </ul>
*/
public void setRetainInstance(boolean retain) {
if (retain && mParentFragment != null) {
throw new IllegalStateException(
"Can't retain fragements that are nested in other fragments");
}
mRetainInstance = retain;
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有