tags:

views:

52

answers:

2

Hey everyone,

I'm writing an android application that maintains a lot of "state" data...some of it I can save in the form of onSaveInstanceState but some of it is just to complex to save in memory.

My problem is that sliding the phone open destroys/recreates the app, and I lose all my application state in the process. The same thing happens with the "back" button, but I overloaded that function on my way. Is there any way to overload the phone opening to prevent it from happening?

Thanks in advance.

A: 

You can try to override the onConfigurationChanged method in your Activity;

or you can try to save your configuration in an overridden onRetainNonConfigurationInstance and retrieve the information in the onCreate by using this.getLastNonConfigurationInstance();

MrThys
+1  A: 

I think the smarter thing to do is to correctly handle the screen-orientation change event and be able to programmatically save and reload your data, rather than trying to fight the phone and the way the OS is intended to work. There is an article in the dev guide titled Faster Screen Orientation Change which you may find useful.

In addition the Shelves sample app deals with this event well, and has a few good examples about cancelling and restoring async tasks when the orientation changes.

matt b