我有這個one.類似的問題,現在我的問題是我不知道要放什麼東西在這裏private int stuff;
第一個答案是給我這個錯誤 'SavedState()' is not public in android.app.Fragment.SavedState'. Cannot be accessed from outside package.
丟失數據。Android的自定義視圖(位圖)旋轉屏幕方向
//no idea what to do here.
private int stuff;
private Bitmap customBitmap;
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh)
{
customBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
customCanvas = new Canvas(customBitmap);
super.onSizeChanged(w, h, oldw, oldh);
}
@Override
protected void onDraw(Canvas canvas)
{
super.onDraw(canvas);
//Draws stuff into the canvas.
canvas.drawBitmap(customBitmap, 0, 0, linePaintOne);
}
@Override
protected Parcelable onSaveInstanceState()
{
Bundle bundle = new Bundle();
bundle.putParcelable("draw", super.onSaveInstanceState());
bundle.putParcelable("bitmap", customBitmap);
bundle.putInt("bitmap", this.stuff);
System.out.println("onSave");
//return super.onSaveInstanceState();
return bundle;
}
@Override
protected void onRestoreInstanceState(Parcelable state) {
if (state instanceof Bundle)
{
Bundle bundle = (Bundle) state;
customBitmap = bundle.getParcelable("bitmap");
this.stuff = bundle.getInt("stuff");
state = bundle.getParcelable("draw");
System.out.println("onRestore1");
}
System.out.println("onRestore2");
super.onRestoreInstanceState(state);
}
事情我嘗試:
•how can I save a bitmap with onRetainNonConfigurationInstance() for screen orientation?
^這個是給我This view's id is id/view. Make sure other views do not use the same id.
。
@Override
protected Parcelable onSaveInstanceState()
{
super.onSaveInstanceState();
Bundle bundle = new Bundle();
bundle.putParcelable("bitmap", customBitmap);
return bundle;
}
@Override
protected void onRestoreInstanceState(Parcelable state) {
super.onRestoreInstanceState(state);
Bundle bundle = new Bundle();
customBitmap = bundle.getParcelable("bitmap");
}
•http://it-ride.blogspot.co.nz/2010/08/save-image-in-instance-state-android.html