I need to finish an android application. For that i wrote
@Override
public void onBackPressed() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Are you sure You want to exit")
.setCancelable(false)
.setPositiveButton("YES"),
new DialogInterface.OnClickListener() {
// On
// clicking
// "Yes"
// button
public void onClick(DialogInterface dialog,int id) {
System.out.println(" onClick ");
closeApplication(); // Close Application method called
}
})
.setNegativeButton("NO"),
new DialogInterface.OnClickListener() {
// On
// clicking
// "No"
// button
public void onClick(DialogInterface dialog,int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
}
private void closeApplication() {
System.out.println("closeApplication ");
this.finish();
}
}
But if any activity is not finished in the application, when i tried to exit the application that activity is finished first and the application is not exiting.. i tried 2 times to exit this application... How i can finish all the activities in an application when i need to exit... or is there any way to finish the entire application
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…