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:Main.java

private static AlertDialog buildErrorDialog(final Activity context, String title, String description,
        String buttonText) {//from  w  w w  .  j  a  v  a2  s  .c  om

    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle(title);
    builder.setMessage(description);
    builder.setCancelable(false);
    builder.setPositiveButton(buttonText, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(final DialogInterface dialog, int which) {
            new Handler().post(new Runnable() {
                @Override
                public void run() {
                    dialog.dismiss();
                    context.finish();
                }
            });
        }
    });

    return builder.create();
}

From source file:mobisocial.musubi.BootstrapActivity.java

/**
 * finishes the caller if bootstrapping is necessary
 * @param activity//www  .j ava  2  s.  co  m
 * @return true if the bootstrap activity will be started
 */
public static boolean bootstrapIfNecessary(Activity activity) {
    if (sBootstrapped) {
        return false;
    }
    Intent intent = new Intent(activity, BootstrapActivity.class);
    intent.putExtra(EXTRA_ORIGINAL_INTENT, (Parcelable) activity.getIntent());
    intent.setFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
    activity.startActivity(intent);
    activity.finish();
    return true;
}

From source file:com.felkertech.n.ActivityUtils.java

public static void openIntroVoluntarily(Activity activity) {
    activity.startActivity(new Intent(activity, Intro.class));
    activity.finish();
}

From source file:org.gplvote.signdoc.MainActivity.java

public static void error(String text, final Activity activity, final boolean parent_exit) {
    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    builder.setTitle(R.string.title_error).setIcon(R.drawable.cancel_icon).setMessage(text).setCancelable(false)
            .setNegativeButton(R.string.btn_ok, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();/*from w  ww  .  j av  a2 s . co m*/
                    if (parent_exit) {
                        activity.finish();
                    }
                }
            });
    AlertDialog alert = builder.create();
    alert.show();
}

From source file:org.quantumbadger.redreader.views.SearchListingHeader.java

private static void performSearch(final Activity parentActivity, final EditText mSubreddit,
        final EditText mQuery) {
    String subreddit = mSubreddit.getText().toString().trim();
    if (StringUtils.isEmpty(subreddit)) {
        subreddit = null;/*  w w w.  j ava  2  s .  c  o  m*/
    }
    SearchPostListURL url = SearchPostListURL.build(subreddit, mQuery.getText().toString().trim());

    final Intent intent = new Intent(parentActivity, PostListingActivity.class);
    intent.setData(url.generateJsonUri());

    // Use a startActivity/finish combination to replace this activity with the new
    // search activity
    parentActivity.startActivity(intent);
    parentActivity.finish();
}

From source file:org.gplvote.signdoc.MainActivity.java

public static void alert(String text, final Activity activity, final boolean parent_exit) {
    final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    builder.setTitle(R.string.title_warning).setIcon(R.drawable.notification_icon).setMessage(text)
            .setCancelable(false).setNegativeButton(R.string.btn_ok, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();/*from  w  ww.ja  v a2 s  . co m*/
                    if (parent_exit) {
                        activity.finish();
                    }
                }
            });
    AlertDialog alert = builder.create();
    alert.show();
}

From source file:io.github.hidroh.materialistic.AppUtils.java

public static void restart(Activity activity, boolean transition) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        activity.recreate();//from w  ww  .j  a v a  2s  .  c o  m
    } else {
        activity.finish();
        if (transition) {
            activity.overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
        }
        activity.startActivity(activity.getIntent());
    }
}

From source file:org.liberty.android.fantastischmemo.utils.AMGUIUtility.java

public static void displayError(final Activity activity, final String title, final String text,
        final Exception e) {
    Log.e(TAG, "displayError", e);
    new AlertDialog.Builder(activity).setTitle(title)
            .setMessage(text + "\n" + activity.getString(R.string.exception_text) + ": "
                    + Throwables.getRootCause(e) + "\n" + Throwables.getStackTraceAsString(e))
            .setPositiveButton(activity.getString(R.string.back_menu_text),
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface arg0, int arg1) {
                            activity.finish();
                        }/*w ww.java  2s.  c om*/
                    })
            .setOnCancelListener(new DialogInterface.OnCancelListener() {
                public void onCancel(DialogInterface dialog) {
                    activity.finish();
                }
            }).show();
}

From source file:de.baumann.browser.helper.helper_main.java

public static void switchToActivity(Activity from, Class to, String Extra, boolean finishFromActivity) {
    Intent intent = new Intent(from, to);
    intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
    intent.putExtra("url", Extra);
    from.startActivity(intent);//from   www.  j av a  2s  . c  om
    if (finishFromActivity) {
        from.finish();
    }
}

From source file:com.dabay6.libraries.androidshared.util.NavigationUtils.java

/**
 * Navigate back up the back stack.//from   ww w .  ja v  a  2 s .  c  o m
 *
 * @param activity The current {@link Activity}.
 */
public static void navigateUp(final Activity activity) {
    // This is called when the Home (Up) button is pressed in the action bar. Create a simple intent that starts the
    // hierarchical parent activity and use NavUtils in the Support Package to ensure proper handling of Up.
    final Intent upIntent = NavUtils.getParentActivityIntent(activity);

    if (NavUtils.shouldUpRecreateTask(activity, upIntent)) {
        // This activity is not part of the application's task, so create a new task with a synthesized back stack.
        TaskStackBuilder.create(activity)
                // If there are ancestor activities, they should be added here.
                .addNextIntent(upIntent).startActivities();
        activity.finish();
    } else {
        // This activity is part of the application's task, so simply navigate up to the hierarchical parent
        // activity.
        NavUtils.navigateUpTo(activity, upIntent);
    }
}