开发者

android saveinstance saving vector datatypes

开发者 https://www.devze.com 2022-12-24 21:02 出处:网络
I am making an application which is currently working perfectly but with only 1 problem... As we all kno开发者_Python百科w that the activity is destroyed and recreated when user changes the orientatio

I am making an application which is currently working perfectly but with only 1 problem... As we all kno开发者_Python百科w 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...


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.
0

精彩评论

暂无评论...
验证码 换一张
取 消