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

Get Learning Android™ Application Programming: A Hands-On Guide to Building Android Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.