How to Quit Android Application Programmatically

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



Leave a reply



Submit