Know the application that is in first or second plane in Android

1

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.

    
asked by Daniel Piad Aldazabal 31.08.2016 в 16:03
source

1 answer

2

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 :

    
answered by 31.08.2016 в 16:46