In My android application, currently one of my activity is focused on the screen. If the user clicked on "HOME" button, which activity method gets invoked.
            Asked
            
        
        
            Active
            
        
            Viewed 1,248 times
        
    0
            
            
        - 
                    "Home button is reserved for the OS as a "last chance" escape for the user from any app. Developers cannot override it, this way ensuring that the user will always have the possibility to leave the app." -> http://stackoverflow.com/questions/6226001/handling-home-button-in-android – Tiago Babo Jun 22 '11 at 12:37
 
3 Answers
1
            You cannot override anything about the Home activity. You can only use the Home intent category.
See this other question for more info:
1
            
            
        There is no way to handle "Home" button click. And this is by design.
Read great post by CommonsWare: Please Ignore the HOME Button. Also see this and this threads on Android Developers group.
        inazaruk
        
- 74,247
 - 24
 - 188
 - 156
 
0
            
            
        Works for me..
@Override
public void onAttachedToWindow() {
    super.onAttachedToWindow();
    this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
}
Then
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if(keyCode == KeyEvent.KEYCODE_HOME){
        // Your code here.
        return true;
    }
    return false;
}
        mDiaz93
        
- 319
 - 3
 - 8
 
- 
                    Works for me on Android 2.3. However it seems to be a hack rather then intended use of API and does not work for me on Android 4. – Miriam Apr 10 '13 at 16:36