Since you're only interested in maintaining state/data between configuration changes, look at these two methods instead:
onRetainNonConfigurationInstance() getLastNonConfigurationInstance() On Nov 9, 7:27 pm, mannyk <[email protected]> wrote: > Hi, > > I am trying to create an app with two view classes - portrait and > landscape. I use the portrait view in my layout.xml and use the > landscape in layout.xml under the layout-land folder. > > My both view classes (portrait and landscape) are essentially the some > bitmap placement differences. My end goal is - to fetch some pictures > in these classes and manipulate them before displaying. I obviously > don't want to refetch the pictures on orientation change, so would > like to pass bitmaps between these views. Is that possible? Here is my > first iteration of one of these view classes and for now I am just > trying to pass an integer between classes. > > My Main Activity is like this: > > public class flipperActivity extends Activity { > /** Called when the activity is first created. */ > @Override > public void onCreate(Bundle savedInstanceState) { > super.onCreate(savedInstanceState); > setContentView(R.layout.main); > } > @Override > protected void onRestoreInstanceState(Bundle savedInstanceState) > { > super.onRestoreInstanceState(savedInstanceState); > } > protected void onSaveInstanceState(Bundle outState) > { > outState.putBoolean("bs", true); > super.onSaveInstanceState(outState); > } > > And my View class is like this: > > public class FlipperVerticalView extends View > { > String time; > Paint paint = new Paint(); > private Bitmap[] pictureArray = new Bitmap[5]; > int i = 0; > boolean forward = true; > public FlipperVerticalView(Context context, AttributeSet attrs) > { > super(context, attrs); > > paint.setColor(Color.BLUE); > paint.setStyle(Paint.Style.FILL); > paint.setAntiAlias(true); > GetPhotoClass getPhotos = new GetPhotoClass(); > pictureArray = getPhotos.GetPhotoArray(); > this.setOnClickListener(new OnClickListener() > { > //change picture index here > }); > } > @Override > protected void onDraw(Canvas canvas) > { > super.onDraw(canvas); > canvas.drawBitmap(pictureArray[i], 20, 20, paint); > } > /*******************SaveState********************************/ > > @Override > public Parcelable onSaveInstanceState() > { > Parcelable superState = super.onSaveInstanceState(); > SavedState ss = new SavedState(superState); > ss.stateToSave = this.i; > return ss; > } > @Override > public void onRestoreInstanceState(Parcelable state) > { > > SavedState ss = new SavedState(state); > super.onRestoreInstanceState(ss.getSuperState()); > > this.i = ss.stateToSave; > } > static class SavedState extends BaseSavedState > { > int stateToSave; > SavedState(Parcelable superState) > { > super(superState); > } > private SavedState(Parcel in) > { > super(in); > this.stateToSave = in.readInt(); > } > @Override > public void writeToParcel(Parcel out, int flags) > { > super.writeToParcel(out, flags); > out.writeInt(this.stateToSave); > } > public static final Parcelable.Creator<SavedState> CREATOR = > new Parcelable.Creator<SavedState>() > { > public SavedState createFromParcel(Parcel in) > { > return new SavedState(in); > } > public SavedState[] newArray(int size) > { > return new SavedState[size]; > } > }; > } > / > *******************EndSaveStateCode***********************************/ > > > > } > }- Hide quoted text - > > - Show quoted text - -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

