How to Exit from the Application and Show the Home Screen

How to exit from the application and show the home screen?

Android's design does not favor exiting an application by choice, but rather manages it by the OS. You can bring up the Home application by its corresponding Intent:

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);

Android application Exit for home screen

Firstly close in an android application is frowned upon because the back button and home button are already kinda giving you this functionality.
But if you need to you can do this

When the user wishes to exit all open activities, they should press a button which loads the first Activity that runs when your app starts.

    Intent intent = new Intent(getApplicationContext(), FirstActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("EXIT", true);
startActivity(intent);

The above code clears all the activities except for first activity. Then put this code inside the first activity's onCreate(), to signal when it should self destruct when the 'Exit' message is passed.

    if (getIntent().getBooleanExtra("EXIT", false)) {
finish();
}

iOS: Exit from the app to Home Screen programmatically with gracefully exit with animation?

Code:

   @IBAction func minimizeOrKillApp(){            
UIControl().sendAction(#selector(URLSessionTask.suspend), to: UIApplication.shared, for: nil)
//Comment if you want to minimise app
Timer.scheduledTimer(withTimeInterval: 0.2, repeats: false) { (timer) in
exit(0)
}
}

Output

Download sample code

It is not recommended and your app will be rejected. We all are the developers and We know to how to approve it from reviewer team

Apple developer question

Close all activities and come to mobile's home screen

You can use this code that I referred from here How to exit from the application and show the home screen?:

  Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);

Although Android's design does not favor exiting an application by choice.

Related Links:

How to close Android application?

Android exit application



Related Topics



Leave a reply



Submit