I currently check to see if my activity’s focus has changed via onWindowFocusChanged() (for example, the home button was pressed or it has switched to a different activity) and if it has, I call finish() on it. My problem is that I only want this to work in the event that the home button was pressed or another activity has been started using startActivity(), but something like a alert dialog can cause the focus to change and consequently finish the activity as well. How can I make the activity finish only when the home button was pressed or another activity has been started using startActivity(), and not when something like a dialog has appeared?
I currently check to see if my activity’s focus has changed via onWindowFocusChanged() (for
Share
If you call
finish()inonStop()that will destroy yourActivitywhen it is no longer visible. A standard dialog will only causeonPause()to be called. Log the activity lifcycle events when they occur and you can check what operations trigger them.