Suppose a user is running an app and then suddenly he closes the app.
Now, will the process in which the app was currently running be immediately killed?
If the answer to the above question is yes then it will mean at the end of some calculation that was being done in my app regarding which I had to save something to the database which could not be done because the process was killed. is it so?
Android guarantees to keep your process while the app has either an active Activity
or a foreground Service
. Right after your Activity
has received onPause()
event and there are no foreground Service
s running, the process hosting your app may be killed at any time, which means that even the onStop()
is not guaranteed to be invoked in some cases. Thus, you should save the important data right in the onPause()
lifecycle callback or use foreground Service
s.
Look here for details: Activity lifecycle, App's process lifecycle