Call method when home button pressed Call method when home button pressed android android

Call method when home button pressed


The Home button is a very dangerous button to override and, because of that, Android will not let you override its behavior the same way you do the BACK button.

Take a look at this discussion.

You will notice that the home button seems to be implemented as a intent invocation, so you'll end up having to add an intent category to your activity. Then, any time the user hits home, your app will show up as an option. You should consider what it is you are looking to accomplish with the home button. If its not to replace the default home screen of the device, I would be wary of overloading the HOME button, but it is possible (per discussion in above thread.)


It took me almost a month to get through this. Just now I solved this issue.In your activity's onPause() you have to include the following if condition:

    if (this.isFinishing()){        //Insert your finishing code here    }

The function isFinishing() returns a boolean. True if your App is actually closing, False if your app is still running but for example the screen turns off.

Hope it helps!


The HOME button cannot be intercepted by applications. This is a by-design behavior in Android. The reason is to prevent malicious apps from gaining control over your phone (If the user cannot press back or home, he might never be able to exit the app).The Home button is considered the user's "safe zone" and will always launch the user's configured home app.

The only exception to the above is any app configured as home replacement. Which means it has the following declared in its AndroidManifest.xml for the relevant activity:

<intent-filter>   <action android:name="android.intent.action.MAIN" />   <category android:name="android.intent.category.HOME" />   <category android:name="android.intent.category.DEFAULT" /></intent-filter>

When pressing the home button, the current home app's activity's onNewIntent will be called.