Android Studio, 2019, Back, twice, 앱 종료(두 번 뒤로가기)

Android 어플 뒤로가기 두번, 어플 종료하기

 

- Mainactivity.class

public class MainActivity extends AppCompatActivity {
    private final long FINISH_INTERVAL_TIME = 2000;
    private long backPressedTime = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
...
   
   }
   
   ...
    @Override
    public void onBackPressed() {
        long tempTime = System.currentTimeMillis();
        long intervalTime = tempTime - backPressedTime;

        if (0 <= intervalTime && FINISH_INTERVAL_TIME >= intervalTime) {
            super.onBackPressed();
        } else {
            backPressedTime = tempTime;
            Toast.makeText(this, "One more", Toast.LENGTH_SHORT).show();
        }
    }

  }

 

이 글을 공유하기

댓글(0)

Designed by JB FACTORY