I want to know if it is possible to know when an app that is being used stops being used: "it closes". I have found a method but it only serves to know when my app is closed, therefore it does not work for me, but I show it to you:
public void onTrimMemory(final int level) {
if (level == ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) {
//SCREEN IS NOT SHOWING
}
From the question: https://stackoverflow.com/questions/33818406/how-to-detected-if-application-is-closed
To define which applications are running on an Android.
ActivityManager.RunningAppProcessInfo is used , for example we can obtain which applications are running, through a BroadcastReciber or by clicking a button call this method which determines which applications are running (prints process name);
It is important to mention that if the application is in "Background" it is considered as active, if you delete it completely it would no longer appear in the list.
To determine if an application is running on an Android device.
To determine this you can also use ActivityManager, as an example a method which receives the context and determines if the application is installed:
An example of how to call the above method:
The same consideration is taken, an application in "background" is considered to be active, this if the operating system has not closed it.
The answer is this code:
https://developer.android.com/reference/android/app/ActivityManager.RunningAppProcessInfo#IMPORTANCE_FOREGROUND_SERVICE