public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public void onBackPressed() {
Log.d("onBackPressed", "touch BackPressed");
twoTimesToExit();
}
private long exitTime;
public void twoTimesToExit() {
if ((System.currentTimeMillis() - exitTime) > 2000) {
Toast.makeText(this, "再按一次退出", Toast.LENGTH_SHORT).show();
exitTime = System.currentTimeMillis();
} else {
this.finish();
System.exit(0);
}
}
}
JAVA android 点击两次返回键退出
最新推荐文章于 2022-11-07 18:24:11 发布