How to close Android application?
Just to answer my own question now after so much time (since CommonsWare commented on the most popular answer telling we should NOT do this):
When I want to quit the app:
- I start my first activity (either splash screen, or whatever activity is currently at the bottom of the activity stack) with
FLAG_ACTIVITY_CLEAR_TOP
(which will quit all the other activities started after it, which means - all of them). Just make to have this activity in the activity stack (not finish it for some reason in advance). - I call
finish()
on this activity
This is it, works quite well for me.
how to close android app completely
To Quit Application
on Button click use this code :
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
startActivity(intent);
Try it..
To kill the complete app and remove it from Running
app list kill the app through its pid
(its nasty)... use this lines before above code.
int pid = android.os.Process.myPid();
android.os.Process.killProcess(pid);
How to close my application programmatically in android?
Whenever you wish to exit all open activities, you should press a button which loads the first Activity that runs when your application starts then clear all the other activities, then have the last remaining activity finish. to do so apply the following code in ur project
Intent intent = new Intent(getApplicationContext(), FirstActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("EXIT", true);
startActivity(intent);
The above code finishes all the activities except for FirstActivity. Then we need to finish the FirstActivity's Enter the below code in Firstactivity's oncreate
if (getIntent().getExtras() != null && getIntent().getExtras().getBoolean("EXIT", false)) {
finish();
}
and you are done....
For More Detail ..exit android application programmatically
How to close an android application?
I found my solution. Use this to close an application
Intent homeIntent = new Intent(Intent.ACTION_MAIN);
homeIntent.addCategory( Intent.CATEGORY_HOME );
homeIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(homeIntent);
exit android application programmatically
Whenever you wish to exit all open activities, you should press a button which loads the first Activity that runs when your application starts then clear all the other activities, then have the last remaining activity finish. to do so apply the following code in ur project
Intent intent = new Intent(getApplicationContext(), FirstActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("EXIT", true);
startActivity(intent);
The above code finishes all the activities except for FirstActivity. Then we need to finish the FirstActivity's Enter the below code in Firstactivity's oncreate
if (getIntent().getExtras() != null && getIntent().getExtras().getBoolean("EXIT", false)) {
finish();
}
and you are done....
From Finish all activities at a time
How to close Android application in Kotlin
Grendel here is the absolute easiest two ways to close the Kotlin App
the first way will open the app on PageTwo when it is reloaded
not elegant but I included on the chance that someone has a Splash Screen
moveTaskToBack(true);
exitProcess(-1)
The second way is so simple and old you are going to scream
It will close the Kotlin App and when reloaded the MainActivity is shown first
finishAffinity()
I tested this with Nexus 9 API 26 I do not have a Samsung Galaxy S2
but feel free to mail me one ha ha
Related Topics
Is There an Addheaderview Equivalent For Recyclerview
How to Use Getdownloadurl in Recent Versions
How to Format Date and Time in Android
Passing a Bundle on Startactivity()
How to Add Dividers and Spaces Between Items in Recyclerview
Changing Locale Within the App Itself
How to Change Fontfamily of Textview in Android
How to Implement Endless List With Recyclerview
Adding a Library/Jar to an Eclipse Android Project
Start Activity from Service in Android
How to Store Image in Sqlite Database
Re-Launch of Activity on Home Button, But...Only the First Time
When to Call Activity Context or Application Context