티스토리 뷰

private final long FINISH_INTERVAL_TIME = 2000;
private long backPressedTime = 0;


메개변수로 상단에 초기화. 




@Override
public void onBackPressed() {
long tempTime = System.currentTimeMillis();
long intervalTime = tempTime - backPressedTime;

if (0 <= intervalTime && FINISH_INTERVAL_TIME >= intervalTime)
{
moveTaskToBack(true);
finish();
android.os.Process.killProcess(android.os.Process.myPid());
super.onBackPressed();

}
else
{
backPressedTime = tempTime;
Toast.makeText(getApplicationContext(), "한번 더 누르시면 앱이 종료됩니다.", Toast.LENGTH_SHORT).show();
}
}