【发布时间】:2014-11-25 07:52:47
【问题描述】:
我有一个 android 应用程序 .. 我想当用户单击退出按钮时,它将显示一条确认消息,如果他单击是,则关闭整个应用程序 ..
试过这段代码,但没有用:
AlertDialog.Builder alertBuilder=new AlertDialog.Builder(AdminEditProfile.this);
alertBuilder.setTitle("Exit");
alertBuilder.setMessage("Are you sure you want to exit from the application?");
alertBuilder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(1);
}
});
alertBuilder.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
alertBuilder.create().show();
有什么办法吗>
请帮忙,谢谢:)。
【问题讨论】:
-
向您发布 log-cat 错误。
-
强行关闭应用是一种不好的做法。请改用
Home和Back按钮。 -
Google 习惯于弃用并最终削弱他们认为被滥用的部分 API。就像在 5.0 中一样,他们添加了一个合法的(但有些有限的)信息亭模式,并消除了人们用来模拟它的黑客攻击。因此,即使您找到了完全退出应用程序的 hack,也不要指望它始终有效。
-
您可以在这里找到答案:stackoverflow.com/a/5036668/1557187
标签: android