在MainActivity中增加以下程式:
private static Boolean isExit = false;
private static Boolean hasTask = false;
Timer tExit;
TimerTask task;
@Overridepublic boolean onKeyDown(int keyCode, KeyEvent event)
{
if (keyCode == KeyEvent.KEYCODE_BACK)
{
mAppWebView.loadUrl(mMenuURL); //自訂返回鍵按下後做的事情
if(isExit==false)
{
isExit=true;
Toast.makeText(this, "再按一次後退鍵退出應用程式",Toast.LENGTH_SHORT).show();
if(!hasTask)
{
hasTask = true;
tExit = new Timer();
task = new TimerTask()
{
@Override
public void run()
{
isExit = false;
hasTask = false;
}
};
tExit.schedule(task, 1000);
}
}
else
{
finish();
System.exit(0);
}
return false;
}
return super.onKeyDown(keyCode, event);
}
沒有留言:
張貼留言