I am new to Android development and I am still not able to understand the onPause()
and onStop()
methods in an activity.
In my app, I have a static class that I name Counter, and it keeps the state of variables in memory for the app. My app runs fine in the emulator. What I was trying to test was differential behavior of onPause()
versus onStop()
.
For onPause
, I wanted the values stored in the Counter class's members retained, whereas calling onStop()
I wanted the counter values reset to zero. So I override onStop()
and set the variables inside the counter class to zero. However, in the emulator, I cannot seem to get the app in the Paused state. In the emulator, I open my app, exercise it. Then I hit the home button (not the back button) of the emulator, and launch another app, believing that this would mimic onPause()
activity. However, the emulator does not appear to honor this (I am using an armeabi v7a emulator), it seems to always be calling onStop()
because my counter values all go back to zero, per my override in onStop()
. Is this inherent to the emulator or am I doing something wrong to get my activity into the paused state?