Question

I want to use quit functionality in my android application. Is there any way to kill all running activities on back button press.Actually i am showing a dialog(contains two buttons) on a button click and by clicking the one of the button on dialog box invokes another activity.But the previous activity by which the dialog is shown, is not finished. Is there any way to finish the activity when i click one of the button of the dialog.

How can i use finish method to end the previous activity.This extends dialog.

@Override

public void onClick(View v) {

    Intent i = new Intent();
    i.setClassName("co.y.c", "co.y.c.activityToStart");
    v.getContext().startActivity(i);
    dismiss();

    });
Was it helpful?

Solution

you can close your app/activity by calling this.finish(). Cleanup should be done within onPause(...) / onFreeze(...) / onDestroy(...) depending on what you want to do.

Regards, Arun Kumar

OTHER TIPS

You can call Activity.finish().

If you don't want the previous Activity to be shown on the back button press, you can specify this in the AndroidManifest.xml like:

<activity android:name="sample.activity.MyActivity" android:noHistory="true" />

This will prevent the Activity from being put into the history stack and allow the back button to quit (assuming you add the noHistory flag to every previous Activity)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top