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

public static void gotoActivity(Activity curActivity, Class<?> targetActivity, boolean finish) {
    Intent intent = new Intent();
    intent.setClass(curActivity, targetActivity);
    curActivity.startActivity(intent);//  w  w w . j  ava  2 s  .  c o  m
    //      curActivity.overridePendingTransition(R.anim.slide_left_in,
    //            R.anim.slide_left_out);

    if (finish) {
        curActivity.finish();
    }
}

From source file:Main.java

/**
 * Alert and quite the activity/*from w  ww.  j  ava  2s.c o m*/
 * @param message
 */
public static void alertAbort(final Activity activity, String message) {
    new AlertDialog.Builder(activity, AlertDialog.THEME_HOLO_DARK).setTitle("Problem...").setMessage(message)
            .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    activity.finish();
                }
            }).setIcon(android.R.drawable.ic_dialog_alert).show();
}

From source file:Main.java

/**
 * Enables back navigation for activities that are launched from the NavBar. See {@code
 * AndroidManifest.xml} to find out the parent activity names for each activity.
 *
 * @param intent/*from   w ww  .ja v  a 2 s  . co m*/
 */
public static void createBackStack(Activity activity, Intent intent) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        TaskStackBuilder builder = TaskStackBuilder.create(activity);
        builder.addNextIntentWithParentStack(intent);
        builder.startActivities();
    } else {
        activity.startActivity(intent);
        activity.finish();
    }
}

From source file:Main.java

public static void showMessageDialogWithFinish(final Activity object, Context context, String message) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setMessage(message).setCancelable(false).setPositiveButton("Ok",
            new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int id) {
                    object.finish();

                }/*from  w w w. j  a va2  s .  co  m*/
            });
    AlertDialog alert = builder.create();
    alert.show();
}

From source file:Main.java

public static void restartClearActivityOutside(Activity activity) {
    if (activity == null)
        return;//from  w w w .  j av a 2s  .c  om
    Context ctx = activity.getApplicationContext();
    Intent intent;
    intent = activity.getIntent();
    intent.addFlags(
            Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_ANIMATION);

    activity.finish();
    activity.overridePendingTransition(0, 0);

    ctx.startActivity(intent);
    activity.overridePendingTransition(0, 0);

}

From source file:gr.scify.newsum.Utils.java

/**
 * Set the theme of the Activity, and restart it by creating a new Activity
 * of the same type.//from www .  j a  v  a  2s .  co  m
 */
public static void changeToTheme(Activity activity, int theme) {
    sTheme = theme;
    activity.finish();

    activity.startActivity(new Intent(activity, activity.getClass()));
}

From source file:at.ac.tuwien.caa.docscan.ActivityUtils.java

/**
 * Enables back navigation for activities that are launched from the NavBar. See {@code
 * AndroidManifest.xml} to find out the parent activity names for each activity.
 *
 * @param intent//from  w w w  . j a v a 2  s .  c  o  m
 */
public static void createBackStack(Activity activity, Intent intent) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        TaskStackBuilder builder = TaskStackBuilder.create(activity);
        builder.addNextIntentWithParentStack(intent);
        builder.startActivities();
    } else {
        activity.startActivity(intent);
        activity.finish();
    }

    //        Use our own animation - instead of the default scaling animation:
    activity.overridePendingTransition(R.anim.translate_in, R.anim.translate_out);
}

From source file:org.solovyev.android.calculator.App.java

public static void restartActivity(@Nonnull Activity activity) {
    final Intent intent = activity.getIntent();
    activity.finish();
    activity.startActivity(intent);//from   w  w w.j  ava 2  s. co  m
}

From source file:com.github.dfa.diaspora_android.util.Helpers.java

public static void animateToActivity(Activity from, Class to, boolean finishFromActivity) {
    Intent intent = new Intent(from, to);
    intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
    from.startActivity(intent);/* w w w  .  ja v  a 2  s  .com*/
    from.overridePendingTransition(R.anim.fadein, R.anim.fadeout);
    if (finishFromActivity) {
        from.finish();
    }
}

From source file:Main.java

public static void standardUp(Activity activity) {
    Intent upIntent = NavUtils.getParentActivityIntent(activity);
    if (NavUtils.shouldUpRecreateTask(activity, upIntent)) {
        TaskStackBuilder.create(activity).addNextIntentWithParentStack(upIntent).startActivities();
    } else {//w  w  w . j ava  2s .c  o m
        upIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        activity.startActivity(upIntent);
        activity.finish();
    }
}