Mouse click

I wanted to call a specific function to display notifications when the homebuttonclick event was clicked.

I referenced this blog.

Written code like:

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

But, unfortunately, it did not work.

I tested through the debugger, but noticed that the debugger also does not execute this line of code when the home button is pressed.

What is wrong with the above code?

Please help me.

+4
source share
4 answers

In the old version of Android, this works. But Android has changed this because they say that the "Home button should remain the Home Button" and they do not want anyone to redefine the Home button. And for this reason, your code no longer works.

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

+7
source
 protected void onUserLeaveHint() { finish(); super.onUserLeaveHint(); } 
+2
source

Key code constant: master key. This key is processed by the infrastructure and is never delivered to applications.

+2
source
 protected void onUserLeaveHint () Added in API level 3 

Called as part of the activity life cycle when an activity is about to go into the background as a result of user selection. For example, when the user presses the Home key, onUserLeaveHint () is called, but when an incoming phone call causes the asset in the call to be automatically brought to the forefront, onUserLeaveHint () will not be called when the activity is interrupted, In cases where it is called , this method is called immediately before the onPause () call is active.

This callback and onUserInteraction () are designed to help actions efficiently manage status bar notifications; in particular, in order to help events determine the appropriate time to cancel the notification.

the code: -

  @Override protected void onUserLeaveHint() { // TODO Auto-generated method stub super.onUserLeaveHint(); new OfflineAsyncTask(BaseActivity.this).execute(); } 
+1
source

All Articles