Home » Android » Catch when Android application went on background

Catch when Android application went on background

Posted by: admin May 14, 2020 Leave a comment

Questions:

I need help with Android.
Here is problem I need to catch event when application went to background.
(ex. home is pressed or any other action that push my app in backgound)
Currently I’m able to catch onPause for activity

@Override
protected void onPause() {
    // TODO Auto-generated method stub
    super.onPause();
}

Is there any override for some event on application level ?

How to&Answers:

From your comment it sounds like you want to know when your program returns from the background, instead of when it goes to the background.

You can use onResume for that. also, see the Activity Lifecycle. You can see the remark “activity comes to the foreground”, which is what I gather from your comment the thing you want.

Note: your activity will call onResume the first time the activity is started, so you might want to set a boolean in onPause to signal your app that it actually went to the background.