kjakeb
kjakeb

Reputation: 7600

onWindowFocusChanged except for dialogs

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?

Upvotes: 1

Views: 1031

Answers (1)

techi.services
techi.services

Reputation: 8533

If you call finish() in onStop() that will destroy your Activity when it is no longer visible. A standard dialog will only cause onPause() to be called. Log the activity lifcycle events when they occur and you can check what operations trigger them.

Upvotes: 1

Related Questions