Having a look at the DroidGap source
I can't see any handling as per what you describe in your question. Orientation changes in the a WebView in more recent versions of the Android fire an onorientationchange
change event at the window level. Some of the older browser implementations don't support this event though so you are left to handle things by capturing the onresize
event. You are best detecting what you have available through feature level detection.
In the source code (which you can download from the Apress site
) I wrote some code which shows an example on how to deal with this. Content is covered in chapter 2.
If you don't want to download the full zip, then you can also have a look at the code on github:
So essentially you capture the orientation changes at the web level with no need for any notifications to be passed through from PhoneGap. This is good as it means your code will work in both a hosted and "native wrapped" app situation.
With regards to the second part of the question (saving instance state) my approach is generally to "serialize as I go". Basically, if I expect that something should be available and remain in the same state if the application was loaded from scratch then I will write a value using HTML5 localStorage (actually, I tend to serialize all my settings together as JSON first and write and read the whole lot together). I then look for these settings (or other state variables) on application load and then restore application state appropriately.
) to delay the save operation for a second or so after the save which ensures that if multiple settings are written the save operation only happens the once. You just do a clearTimeout
followed by a setTimeout
to clear an reset the timer delay on each setting write.
As far as content on this topic in the book goes, Chapter 3 and 4 cover using localStorage and the Web SQL database to save data, but not primarily around the topic of managing application state (although the JSON serialization technique I spoke about is covered). As per previous threads, I might see if I can put some content on the topic of "Managing application state through local storage" online somewhere. The books focus is primarily on managing application data.
Hope that makes sense, and answers both your questions Daniel.