【发布时间】:2014-06-13 13:23:06
【问题描述】:
Logcat:
06-13 18:25:37.534: E/WindowManager(420): Activity com.dimensionsco.thankbunny.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@43ef3c98 that was originally added here
这是我用来退出带有警报对话框的应用程序的代码。但它最终会出现错误。我不明白我哪里出错了。我在模拟器上运行它。任何人都可以解决这个问题吗?提前致谢
@Override
public void onStop() {
super.onStop();
Toast.makeText(getBaseContext(), "stop", Toast.LENGTH_LONG).show();
AlertDialog.Builder alertDialogBuilde = new AlertDialog.Builder(MainActivity.this);
alertDialogBuilde.setTitle(this.getTitle() + "EXIT");
alertDialogBuilde.setMessage("DO you want to exit?");
AlertDialog alertDialogr = alertDialogBuilde.create();
alertDialogBuilde.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// go to a new activity of the app
dialog.cancel();
// finish();
}
});
alertDialogBuilde.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
// set neutral button: Exit the app message
alertDialogBuilde.setNeutralButton("Exit the app", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// exit the app and go to the HOME
System.exit(0);
// MainActivity.this.finish();
}
});
alertDialogr.show();
}
【问题讨论】:
-
请发布logcat
-
这:
System.exit(0);太可怕了。不要那样做。 -
@323go kk,我会用finish()替换
-
有人能建议如何在这里发布日志猫数据吗?
-
复制重要部分,编辑您的问题并将其放入代码块中。并且永远不要使用
System.exit(0);,它只会弄乱你的应用程序。