Search code examples
androiddialogkillback-buttonactivity-finish

how to implement quit functionality in android application


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

    });

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