Android – use onbackpressed() with backward compatibility

I want to use onbackpressed() method. I still hope to provide support for Android SDK before 2.0. Onbackpressed() was introduced in Android SDK 2.0. But what should I do?

resolvent:

Use onkeydown;

public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {

          // Your Code Here

        return true;
    }
    return super.onKeyDown(keyCode, event);
}

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
分享
二维码
< <上一篇
下一篇>>