안드로이드 백버튼 두번 누른 후 앱 종료동작


public class MainActivity extends Activity {
private Context mContext = null;
private long backKeyPressedTime = 0;


@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

mContext = this;
}

@Override
public void onBackPressed() {
if (System.currentTimeMillis() > backKeyPressedTime + 2000) {
backKeyPressedTime = System.currentTimeMillis();
Toast.makeText(this, "\'뒤로\'버튼을 한번 더 누르시면 종료됩니다.", Toast.LENGTH_SHORT).show();
return;
}
if (System.currentTimeMillis() <= backKeyPressedTime + 2000) {
super.onBackPressed();
}
}



728x90
반응형

+ Recent posts