Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Home button click event handling android

Tags:

android

I wanted to call certain function for showing notifications on pressing of homebuttonclick event.

I refered this blog.

Written code as:

@Override
    public boolean onKeyDown(int keyCode, KeyEvent event){
        if(keyCode == KeyEvent.KEYCODE_HOME){
            APP_STATUS="SLEEP";

          LocalToNotification();

        }
        return true;
    }   

But unfortunatly it was not working.

I tested through debugger, but observed that debugger is also not comming on this line of code upon pressing home button.

What is wrong in above code?

Please help me.

like image 811
C Sharper Avatar asked Dec 12 '22 11:12

C Sharper


1 Answers

On older Android version this is working. But Android changed this, because they say "Home Button should stay Home Button" and they don't want that anybody override the Home Button. And because of this reason your code is not working anymore.

If you want to do something when the home button is pressed, then do this in the onPause method.

like image 111
silvia_aut Avatar answered Dec 21 '22 11:12

silvia_aut