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

protected static void delayFinish(final Activity activity, long delay) {
    new CountDownTimer(delay, 100) {
        @Override//from ww w  . jav  a2  s  .c o  m
        public void onTick(long millisUntilFinished) {
            // do nothing
        }

        @Override
        public void onFinish() {
            activity.finish();
        }
    }.start();
}

From source file:Main.java

/**
 * Function use through the app to show Toast information and finish current activity.
 * Function is called so often from background, that it's content is explicitly called from UIThread.
 *
 * @param activity         - is current activity to finish
 * @param stringResourceId of text we show
 * @param handler          to UIThread/*from w w  w  .jav  a  2 s  . c o  m*/
 */
public static void showToastAndFinishActivity(final Activity activity, final int stringResourceId,
        Handler handler) {
    handler.post(new Runnable() {
        @Override
        public void run() {
            Toast.makeText(activity, activity.getString(stringResourceId), Toast.LENGTH_SHORT).show();
            activity.finish();
        }
    });
}

From source file:Main.java

public static void recreate(@NonNull Activity activity) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        activity.recreate();/*w  w  w. j av a 2  s . com*/
    } else {
        Intent intent = activity.getIntent();
        intent.setClass(activity, activity.getClass());
        activity.startActivity(intent);
        activity.finish();
        activity.overridePendingTransition(0, 0);
    }
}

From source file:Main.java

public static void goHome(Activity currentActivity, Class<?> homeActivityClass) {
    Intent parentActivityIntent = new Intent(currentActivity, homeActivityClass);
    parentActivityIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
    currentActivity.startActivity(parentActivityIntent);
    currentActivity.finish();
}

From source file:Main.java

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

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

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

}

From source file:Main.java

public static void restartApp(Activity activity) {
    if (activity == null) {
        return;/*from w  ww . ja  v a 2 s.c  o  m*/
    }
    Intent i = activity.getBaseContext().getPackageManager()
            .getLaunchIntentForPackage(activity.getBaseContext().getPackageName());
    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    activity.startActivity(i);
    activity.finish();
}

From source file:com.samknows.measurement.util.LoginHelper.java

public static void openMainScreen(Activity acc) {
    Intent intent = new Intent(acc, SamKnowsAggregateStatViewerActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
    acc.startActivity(intent);/*from   www.j av  a 2s  .c  om*/
    acc.finish();
}

From source file:Main.java

public static void finishActivityWithSetting(Activity paramActivity, String paramString1, String paramString2) {
    if (paramString1 != null) {
        Intent localIntent = new Intent();
        localIntent.putExtra("setting_raw", paramString1);
        localIntent.putExtra("setting_label", paramString2);
        paramActivity.setResult(-1, localIntent);
    }/*w w  w.j av  a 2  s .c  o m*/
    paramActivity.finish();
}

From source file:Main.java

/**
 * Restart the Activity//from w  w  w  .  j  a  v  a 2s.com
 *
 * @param activity
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static void restartActivity(Activity activity) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        activity.recreate();
    } else {
        Intent intent = activity.getIntent();
        activity.overridePendingTransition(0, 0);
        intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
        activity.finish();

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

From source file:com.dockerandroid.ui.activity.MainActivity.java

public static void openMainActivity(Activity activity) {
    UIController.startActivity(activity, MainActivity.class);
    activity.finish();
}