How to Exit an Android App 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

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.

How to Exit an application when my app consists of multiple activities?

call finishAffinity(); method to finish all the previous activities.

 finishAffinity();

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 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 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 Runningapp 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);


Related Topics



Leave a reply



Submit