When to save data to a database, onPause () or onStop ()?
Or. They are almost identical, especially on Android 3.0+.
If the action that captures the foreground is a typical full-screen activity, so that the earlier activity is no longer visible, onPause() and onStop() will be called in quick succession.
If the action performing the foreground looks more like a dialog in which an earlier activity is still visible, onPause() will be called but not onStop() until the activity is a longer view (for example, now user presses HOME).
Most applications are not bothered by the "themed to like like dialog" script, in which case onPause() and onStop() are called one immediately after the next, and you can expand your background thread to save your data depending on what makes sense for you.
However, in many places in the Android documentation, they always suggest that you do not do heavy work (for example, writing data to the database) in the onPause () method, since this delays the transition between actions.
The same goes for onStop() , since both of these methods are called in the main thread of the application.
So, can we assume that any Android device (including different ROMS) will provide an onStop call regarding activity?
Both onPause() and onStop() will have the same characteristics in terms of process termination. Any of them must be called (a normal case), or none of them will be called (for example, you crash, the battery pushes the back of the phone).
And is this the best place to record time in the App Store app?
Either onPause() or onStop() are great places to start work done in the background thread to save your data. If you prefer to do this work in onStop() , you can do it. Personally, I'm the onPause() guy.