I would like to pausing or putting the application on background when pressing the back button, I don't want the application to go through the destroy state. Things are when I override onKeyDown and when I force to pause or stop the application by using onPause, I have some issuees with the wakelock and application crash, but when I press home button I go through onPause method and I have no exception, it's weird!!
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Try to use the method onBackPressed(), like this:
@Override public void onBackPressed() { moveTaskToBack(true); }
回答2:
The answer is
public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { moveTaskToBack(true); return true; // return } return false; }
回答3:
@Override public void onBackPressed() { if(mWebView.canGoBack()) mWebView.goBack(); else //super.onBackPressed(); moveTaskToBack(true); }