728x90
package com.example.backbuttonexample;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
private long backBtnTime = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public void onBackPressed() {
long curTime = System.currentTimeMillis();
long gapTime = curTime - backBtnTime;
//이 시간내에 누르게 되면 앱이 꺼짐
if(0 <=gapTime && 2000>=gapTime){
super.onBackPressed();
}
else{
backBtnTime = curTime;
Toast.makeText(this,"한번 더 누르면 종료됩니다요",Toast.LENGTH_SHORT).show();
}
}
}
728x90
'✍2021,2022 > app(android studio)' 카테고리의 다른 글
앱만들기.24(인스타 하단바 bottom navigation view) (0) | 2021.07.29 |
---|---|
앱만들기.23(google map) (0) | 2021.07.21 |
앱만들기.21(MP3) (0) | 2021.07.21 |
앱만들기.19 (spinner드롭다운) (0) | 2021.07.20 |
앱만들기.18(FCM푸시알림) (0) | 2021.07.19 |