Learning Android™ Application Programming: A Hands-On Guide to Building Android Applications
by James Talbot, Justin McLean, Jorge Hernandez
Handling Orientation Changes
The onDestroy method is called because you have different layouts for portrait and landscape modes and therefore the activity needs to be re-created. This is not what you want to happen. How can you stop the onDestroy method from being called?
One solution is to handle the orientation change in your code: You set android:configChanges="orientation" in the manifest file. But that requires more work, because you will then need to handle all the layout changes yourself. This could get burdensome after a while.
Another solution is to save the timer when onConfigurationChanged is called, but this could also entail subtle complexities that could be difficult to deal with. It’s best to avoid complexity wherever you can. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access