I need to know the application that is in the foreground in android, that is to say, to know the app that is at a given moment open, showing on the screen, let's say.
I need to know the application that is in the foreground in android, that is to say, to know the app that is at a given moment open, showing on the screen, let's say.
This you can only know in the same application, not from another application.
Overwrite the onResume()
method of your Activity
:
@Override
protected void onResume() {
super.onResume();
//La app esta en primer plano (foreground).
}
to know if your application stopped being in "close-up", that is to say that it is minimized, you can do it using the method onPause()
:
@Override
protected void onPause() {
super.onPause();
//La app esta en segundo plano (background).
}
You can see this in the life cycle diagram of your Actvity
: