-3

Is there a way to determine when another app was closed on android?

Unfortunately, I don't have control of the app in question and as far as I am aware there are no events specific to that app that I can listen for.

By "closed," I mean that said app goes from being visible and in the foreground to not being visible and in the foreground. So this event could be caused by pressing the home button, or the back button until the app disappears, or clicking on a link in the app which causes another app to gain focus.

Basically, I want to detect when a specific app has been closed and either display a notification or pop up a small overlay on the screen.

bleush
  • 3
  • 3
  • 1
    Apps aren't "closed" on Android. So, you may wish to provide a better definition of the event that you are seeking. – CommonsWare May 12 '15 at 15:57
  • Android isn't designed to support this - you will be in a constant battle with the system. If it is you own app, add reporting hooks to onPause() or onStop(), otherwise **pick a better project to spend your time on**. – Chris Stratton May 12 '15 at 15:59

1 Answers1

0

I'd suggest looking for the process name related to a specific app. Poll that list. If you see that app's name on one poll, and on a subsequent poll that app's name is no longer present, that app has been closed.

However, Android will keep an app 'open' as long as possible rather than terminate the process, so this may not be a good route.

I'd go this route myself: Determining the current foreground application from a background task or service

Community
  • 1
  • 1
William Morrison
  • 10,953
  • 2
  • 31
  • 48