本文介绍了Android的 - 确认应用程序退出烤面包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是新的Android开发,我想它,以便当用户presses的主要活动的返回按钮,会出现一个确认退出由$ P $再次pssing返回按钮消息举杯消息。我将如何做到这一点?这是我到目前为止有:
@覆盖
公共无效onBack pressed(){
// TODO自动生成方法存根
super.onBack pressed();
吐司S = Toast.makeText(getBaseContext(),回来了preSS退出,Toast.LENGTH_LONG);
s.show();
等待();
公共布尔onBack pressed(){
完();
}
}
解决方案
我只想救背面preSS的时间,然后最新preSS的时间比较新的preSS。
终于preSS;
@覆盖
公共无效onBack pressed(){
长currentTime的= System.currentTimeMillis的();
如果(currentTime的 - 最后preSS> 5000){
Toast.makeText(getBaseContext(),回来了preSS退出,Toast.LENGTH_LONG).show();
最后preSS = currentTime的;
}其他{
super.onBack pressed();
}
}
I'm new to Android development and I want it so when the user presses the back button on the main activity, a toast message appears with a "confirm exit by pressing the back button again" message. How would I do this? This is what I have so far:
@Override
public void onBackPressed() {
// TODO Auto-generated method stub
super.onBackPressed();
Toast s = Toast.makeText(getBaseContext(), "Press back again to exit", Toast.LENGTH_LONG);
s.show();
wait();
public boolean onBackPressed() {
finish();
}
}
解决方案
I would just save the time of the backpress and then compare the time of the latest press to the new press.
long lastPress;
@Override
public void onBackPressed() {
long currentTime = System.currentTimeMillis();
if(currentTime - lastPress > 5000){
Toast.makeText(getBaseContext(), "Press back again to exit", Toast.LENGTH_LONG).show();
lastPress = currentTime;
}else{
super.onBackPressed();
}
}
这篇关于Android的 - 确认应用程序退出烤面包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!