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
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 programmatically quit an android application and then reopen it?
I dont think you need to kill the app instead clear application data !! Try this ..
private void clearAppData() {
try {
// clearing app data
if (Build.VERSION_CODES.KITKAT <= Build.VERSION.SDK_INT) {
((ActivityManager)getSystemService(ACTIVITY_SERVICE)).clearApplicationUserData(); // note:it has a return value!
} else {
String packageName = getApplicationContext().getPackageName();
Runtime runtime = Runtime.getRuntime();
runtime.exec("pm clear "+packageName);
}
} catch (Exception e) {
e.printStackTrace();
}
}
How to quit an application programmatically through button click
use this code...i hope this will help you..
quitBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View paramView)
{
finish();
moveTaskToBack(true);
}
});
How to Exit an application when my app consists of multiple activities?
call finishAffinity(); method to finish all the previous activities.
finishAffinity();
Programmatically Exit Android Application Without finish()
Use finish()
in your splash screen just before you create your second activity
, then use finish()
is the second activity
: that will not bring back the splash screen.
Related Topics
Download Failed Because the Resources Could Not Be Found
How to Check If a Value Exists Already in a Firebase Data Class Android
How to Delete or Remove Cardview from Recyclerview - Android Studio
How to Set Button Click Effect in Android
Possible Unhandled Promise Rejection (Id:0) Error: Network Error in React Native
How to Get the Current Time on a Button Click
How to Edit Files Inside the Android Adb Shell
Getting the Current Fragment Instance in the Viewpager
Html File Input Control With Capture and Accept Attributes Works Wrong
How to Get the Result of Onpostexecute() to Main Activity Because Asynctask Is a Separate Class
How to Make User Login from Only One Device At a Time
How to Disable Preveious Date in a Date Picker
How to Make a New Line or Tab in <String> Xml (Eclipse/Android)
How to Avoid the Frame Layout Is Pushed Up When the Soft Keyboard Appears
How to Enable Location Access Programmatically in Android
How to Get the Height of Recyclerview Item in "Onbindviewholder"
How to Automatically Open App When Receive Push Notification