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)
}
}
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
Save Arraylist to Sharedpreferences
How to Send an Object from One Android Activity to Another Using Intents
How to Load an Imageview by Url in Android
How to Access My Localhost from My Android Device
How to Connect to Android With Adb Over Tcp
Auto Scale Textview Text to Fit Within Bounds
How to Start New Activity on Button Click
Programmatically Obtain the Phone Number of the Android Phone
Checking If an Android Application Is Running in the Background
How to Retrieve Data from Firebase to My Adapter
Android Activity Life Cycle - What Are All These Methods For
Synchronise Scrollview Scroll Positions - Android
How to Change the Font on the Textview