choco choco - 1 year ago 182
Android Question

exit android application programmatically

I have two activities, the first is a splash activity.
I would like to know how to exit the application from the second activity to the homepage.
I've used this method it works BUT it takes to the launcher.

public void AppExit()

Intent intent = new Intent(Intent.ACTION_MAIN);


Answer Source

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.putExtra("EXIT", true);

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)) {

and you are done....

From Finish all activities at a time

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download