views:

119

answers:

1

hi friends, 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...

Thanx...

+2  A: 

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.
Roman Nurik
WOW!! Thanx Roman Nurik... it worked like a charm... though my my problems solved but can we store more than 1 object like the way u explained... coz it returns only the last copnfiguration... so i guess it stores only 1 object... correct me if i'm wrong... thanx again...
JaVadid