I got confused after reading the Android doc about isFinishing()
at http://developer.android.com/reference/android/app/Activity.html.
If I call isFinishing()
in onPause()
, what would the return value of the isFinishing()
call be in the following 3 scenarios?
finish()
being called.I am sure that the result of isFinishing()
will be true in scenario 1 and will be false in scenario 3.
How about scenario 2? Will isFinishing()
return true or false in scenario 2?
Android only kills processes. Unless you do something special, all of your activities are running in the same process, so can only all be killed together. Regardless, isFinishing() tells you if the activity is actually finishing. That is, the user can never return to it.
Using activity. isFinishing() is the right one solution. it return true if activity is finished so before creating dialog check for the condition. if true then create and show dialog.
Your Activity doesn't get killed by the OS while it's in the foreground. That wouldn't make sense.
However, if the activity goes to the background because the user switched to a different app, it could get killed after onPause()
has been processed. As such, you could get isFinishing() == false
as the user switches to a new app, but then the app is killed.
As the doc says, save all persistent data in onPause()
. onDestroy()
is not guaranteed to be called.
(I wouldn't be surprised if Dianne steps in and corrects me here, btw.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With