Android – what method do I call when I press the back button on my phone?

I have an application with many activities, which are created with onactivityresult

Which method is called when I press the back key?

I need to know it because I have to override / implement the code

resolvent:

The required method is: onkeydown. Of the current activity

You can use it to locate all Android versions:

@Override
public boolean onKeyDown(int keyCode, KeyEvent event)  {
      if (keyCode == KeyEvent.KEYCODE_BACK) {
          return true;
      }

   return super.onKeyDown(keyCode, event);
}

If you want to locate newer Android devices, Android 2.0 and later APIs will make things easier:

@Override
public void onBackPressed() {
    return;
}

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>