Save and Restore instance state

Put your problem here if it does not fit any of the other categories.

Save and Restore instance state

Postby nicholas.hauschild » Sun Jun 27, 2010 2:01 am

Hey gang,

I have run into some trouble lately with onSaveInstanceState() and onRestoreInstanceState(). I have multiple activities that do this to save state in the case that they are cleaned up by the system. Most of them work, except for one, and I have no idea why.

What specifically happens is this:
--I have my emulator running, and the dev tools setup to destroy() all activities when they are no longer visible. (So that I can prove that save/restore are working properly.)
--The Activity in question is started up, and I proceed to change some of its state.
--I start a new Activity, let it run for a moment, and then use the 'back' button to go to my previous Activity.
--Upon arriving back at the Activity in question, I notice that the default state is back, thus, it does not have the state it should.

I have noticed that the onSaveInstanceState() is called, onCreate() is called, but has a null bundle, and onRestoreInstanceState() is never called.

Has anyone seen this before?

Thanks!
-Nick
nicholas.hauschild
Master Developer
Master Developer
 
Posts: 310
Joined: Fri Dec 04, 2009 4:50 am

Top

Re: Save and Restore instance state

Postby vik » Sun Jun 27, 2010 7:05 pm

i am not quitee sure about this but had faced a similar problem.... now in your case try n chk the bundle in onSaveinstance .... another case is whatever you want to save get it some ID dont let it be without id sometimes even that solves the prob...
User avatar
vik
Senior Developer
Senior Developer
 
Posts: 141
Joined: Wed Sep 09, 2009 7:32 am

Re: Save and Restore instance state

Postby nicholas.hauschild » Mon Jun 28, 2010 1:27 pm

I believe I have figured out the issue, and it is with details that I did not disclose in the original question.

One of the things I am saving in my bundle is quite large (a 500x1000 pixel Bitmap). When I removed that from my Bundle, everything else was saved, the onCreate() method was called with the Bundle, and onRestoreInstanceState() was called as well.

Thus I believe there is a maximum size Bundle that you can save in onSaveInstanceState(), which is not documented. (at least as far as I can tell)
nicholas.hauschild
Master Developer
Master Developer
 
Posts: 310
Joined: Fri Dec 04, 2009 4:50 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Google [Bot] and 17 guests