Example usage for android.app Activity finish

List of usage examples for android.app Activity finish

Introduction

In this page you can find the example usage for android.app Activity finish.

Prototype

public void finish() 

Source Link

Document

Call this when your activity is done and should be closed.

Usage

From source file:cat.ereza.customactivityoncrash.CustomActivityOnCrash.java

/**
 * Closes the app./*from   w w w. j a  v a  2s .  c o m*/
 * If an event listener is provided, the close app event is invoked.
 * Must only be used from your error activity.
 *
 * @param activity      The current error activity. Must not be null.
 * @param eventListener The event listener as obtained by calling getEventListenerFromIntent.
 */
public static void closeApplication(Activity activity, EventListener eventListener) {
    if (eventListener != null) {
        eventListener.onCloseAppFromErrorActivity();
    }
    activity.finish();
    killCurrentProcess();
}

From source file:com.gm.goldencity.util.Utils.java

/**
 * Exit with finish context/*w  ww  .j  a va2  s . c  om*/
 *
 * @param context Context of activity of an activity
 */
public static void exit(Context context) {
    Activity activity = (Activity) context;
    activity.finish();
}

From source file:com.eleybourn.bookcatalogue.dialogs.StandardDialogs.java

/**
 * Show a dialog asking if unsaved edits should be ignored. Finish if so.
 *//*ww w  . j  ava2 s .co m*/
public static void showConfirmUnsavedEditsDialog(final Activity a, final Runnable r) {
    AlertDialog.Builder dialog = new Builder(a);

    dialog.setTitle(R.string.details_have_changed);
    dialog.setMessage(R.string.you_have_unsaved_changes);

    dialog.setPositiveButton(R.string.exit, new AlertDialog.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
            if (r != null) {
                r.run();
            } else {
                a.finish();
            }
        }
    });

    dialog.setNegativeButton(R.string.continue_editing, new AlertDialog.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    dialog.setCancelable(false);
    dialog.create().show();
}

From source file:com.wujilin.doorbell.starter.ActivityStarter.java

@Override
protected void exit(Activity starter) {
    starter.finish();
}

From source file:com.yanzhenjie.album.mvp.BaseFragment.java

@Override
public void bye() {
    Activity activity = getActivity();
    if (activity != null)
        activity.finish();
}

From source file:com.tingtingapps.securesms.PlayServicesProblemFragment.java

private void finish() {
    Activity activity = getActivity();
    if (activity != null)
        activity.finish();
}

From source file:org.deviceconnect.android.manager.setting.ErrorDialogFragment.java

@Override
public void onStop() {
    super.onStop();

    Activity activity = getActivity();
    if (activity != null) {
        activity.finish();
    }//  w  w w  . j a  v  a 2 s  .  com
}

From source file:cat.ereza.customactivityoncrash.CustomActivityOnCrash.java

/**
 * Given an Intent, restarts the app and launches a startActivity to that intent.
 * The flags NEW_TASK and CLEAR_TASK are set if the Intent does not have them, to ensure
 * the app stack is fully cleared./*from   w  ww.  j  a v a  2 s  . c o  m*/
 * If an event listener is provided, the restart app event is invoked.
 * Must only be used from your error activity.
 *
 * @param activity      The current error activity. Must not be null.
 * @param intent        The Intent. Must not be null.
 * @param eventListener The event listener as obtained by calling getEventListenerFromIntent.
 */
public static void restartApplicationWithIntent(Activity activity, Intent intent, EventListener eventListener) {
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    if (eventListener != null) {
        eventListener.onRestartAppFromErrorActivity();
    }
    activity.finish();
    activity.startActivity(intent);
    killCurrentProcess();
}

From source file:com.mobicage.rogerthat.util.ui.UIUtils.java

public static void showErrorDialog(final Activity activity, Intent intent) {
    final String errorMessage = intent.getStringExtra(ERROR_MESSAGE);
    if (TextUtils.isEmptyOrWhitespace(errorMessage)) {
        activity.finish();
        UIUtils.showErrorToast(activity, activity.getString(R.string.scanner_communication_failure));
    } else {// w  ww  .j  a  va 2s .c o m
        final String errorCaption = intent.getStringExtra(ERROR_CAPTION);
        final String errorAction = intent.getStringExtra(ERROR_ACTION);
        final String errorTitle = intent.getStringExtra(ERROR_TITLE);

        SafeDialogClick positiveButtonListener = new SafeDialogClick() {
            @Override
            public void safeOnClick(DialogInterface dialog, int id) {
                dialog.dismiss();
                activity.finish();
            }
        };
        SafeDialogClick negativeButtonListener = null;
        if (!TextUtils.isEmptyOrWhitespace(errorCaption) && !TextUtils.isEmptyOrWhitespace(errorAction)) {
            negativeButtonListener = new SafeDialogClick() {
                @Override
                public void safeOnClick(DialogInterface dialog, int id) {
                    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(errorAction));
                    dialog.dismiss();
                    activity.finish();
                    activity.startActivity(intent);
                }
            };
        }
        UIUtils.showDialog(activity, errorTitle, errorMessage, positiveButtonListener, errorCaption,
                negativeButtonListener);
    }
}

From source file:com.wujilin.doorbell.starter.FragmentStarter.java

@Override
protected void exit(Fragment starter) {
    if (starter instanceof DialogFragment) {
        DialogFragment fragment = (DialogFragment) starter;
        if (fragment.getShowsDialog()) {
            fragment.dismiss();// w  w w .  j  a v  a  2 s  . c om
            return;
        }
    }
    Activity activity = getActivity();
    if (activity != null) {
        activity.finish();
    }
}