*バックボタンの長押しでアプリケーションを終了させる。
(If back button is long pressed, application is finised.)
AndroidOS version 1.6
// If backButton is long pushed , variable set true. otherwise false.
private boolean isBackButtonLongPressed = false;
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (KeyEvent.KEYCODE_BACK == keyCode && 3 < event.getRepeatCount()) {
Log.d(LOG_TAG, "onKeyDown() : back button is long pressed.");
isBackButtonLongPressed = true;
}
return true;
}
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
if (!isBackButtonLongPressed) {
isBackButtonLongPressed = false;
} else {
applicationFinish();
}
return true;
}
/**
* Application is finished.
* All process will be killed.
*/
private void applicationFinish() {
Log.d(LOG_TAG, "applicationFinish() : aplication is finished. All processes killed");
System.exit(RESULT_OK);
}
API:http://developer.android.com/reference/android/view/KeyEvent.html
上記(戻るボタン長押し)の他に、HomeButton押下時もプロセスを切る処理は入れるべきでしょう。
0 件のコメント:
コメントを投稿