Android - Disable Device Back button

天大地大妈咪最大 提交于 2019-12-29 05:33:05

问题


I am working on android application using PhoneGap. I need to handle Device back button functionality by using the below code:

 import com.phonegap.DroidGap;
 public Class MyClass extends DroidGap {
 appView.setOnKeyListener(new OnKeyListener() { 
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP) {
                finish();
                return true;
            }
            return onKeyDown(keyCode, event); 
        } 
    });
  }

By using the above code, Application getting exited because i have used finish(); But i want nothing should be happened on click of Device back button. How can i acheive that? Please help me.


回答1:


Why do you need to do this at the Java level? You can achieve this with Javascript using Phonegap's Event API

document.addEventListener("backbutton", onBackKeyDown, false);
function onBackKeyDown(e) {
  e.preventDefault();
}


来源:https://stackoverflow.com/questions/17875299/android-disable-device-back-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!