I am making an application which is currently working perfectly but with only 1 problem... As we all know that the activity is destroyed and recreated when user changes the orientation of the phone... my activity needs to save a vector full of objects wen the activity is recreated... i checked the OnSaveInstance() method and found that there is no way a vector can be stored... Does any1 have a suggestion for storing vector so that i can retrieve it on recreation of Activity???

Any help will be appreciated...


Was it helpful?


Yep, there's a mechanism in place for this purpose.

  1. Implement/override onRetainNonConfigurationInstance in your Activity class, returning the state object you want to persist across orientation changes (in this case, a vector or what not)
  2. In your onCreate or onStart or what not, access the stored object by calling getLastNonConfigurationInstance. If it's null, recreate the object.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow