How to close app when clicking a Dialog in Mainactivity?

Asked

Viewed 173 times

0

My app has several activitys.

Some of them have a Dialog that when clicking on it, the application goes back to Mainactivity.

I want when you click yes in the Mainactivity Dialog, the application is closed.

What happens is that when I click yes, the application goes back to Activity that was opened earlier.

How do I close the app by clicking the Mainactivity dialog?

  • Enter your Mainactivity code so we know what you did wrong.

1 answer

1

The function below closes in a simple way, and even cleans the entire java machine dedicated to the application execution. However, you should call it from the main activity, otherwise Android can restart your application automatically. (Tested this on Android 7.0). It should instantly terminate the Linux process and all application threads.

Call this function from your Dialog:

public void exit(){
  System.exit(0);
}

It instantly makes a good output without telling the user that the application failed.

  • I had already used it. It didn’t work. is because it is a quiz, starts on the main screen, goes to the question screen and to the right/wrong screen and back to the question screen. goes back and forth on these two screens and all of them have a Dialog that, if you click yes, on the question screen and right/wrong, I put a startActivity to go back to the main screen and also erase the bank points, and on the main screen, if you click yes, I want you to close the app for good. but when I click it goes back to screen you ask.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.