2

I want to know when a user exits a certain activity, such as by: - Navigating to another activity within the same app - Exiting the app - Putting the phone to sleep

What are ways to detect the above, and maybe other possibilities?

onepiece
  • 2,999
  • 6
  • 40
  • 58
  • http://stackoverflow.com/questions/1843911/android-detect-when-another-activity-is-launched-or-your-activity-loses-focus – Robert Harvey May 31 '13 at 22:47

1 Answers1

1

You can simply use LifeCycle events such as onDestroy() or onStop() you can override them in your activity

MicroRJ
  • 165
  • 9
  • 1
    You can also user onUserLeaveHint() I believe. Very good for detecting when the user leaves the app. – MicroRJ Jul 02 '19 at 14:33