Shutting down the application
Smartphones' batteries are very limited making mobile devices very sensitive to any background activities they run. Our previous application samples stayed alive after the user switched to another activity. This means that instead of respecting the Android activity lifecycle (http://developer.android.com/training/basics/activity-lifecycle) and pausing our application, we continued to waste precious system resources in the background. It's time we learnt how to handle the onPause()
Android callback in our native code.
Getting ready
If you are not familiar with Android Activity lifecycle, refer to the developer manual: http://developer.android.com/training/basics/activity-lifecycle/index.html.
How to do it…
An Android application does not have to implement all of the lifecycle methods. Our strategy for lifecycle management will be very simple; save game state and terminate an application once the
onPause()
method is called. We need to write some Java code to make...