Android examples for Activity:Activity Restart
restart Activity Later
//package com.java2s; import android.app.Activity; import android.content.Intent; import android.os.Handler; import android.os.Looper; public class Main { public static void restartLater(final Activity thiz, final Intent intent) { Handler handler = new Handler(Looper.getMainLooper()); handler.post(new Runnable() { @Override/*from w w w . java2 s . co m*/ public void run() { restart(thiz, intent); } }); } public static void restart(final Activity thiz) { restart(thiz, thiz.getIntent()); } public static void restart(final Activity thiz, Intent intent) { intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); thiz.overridePendingTransition(0, 0); thiz.startActivity(intent); thiz.overridePendingTransition(0, 0); int flags = intent.getFlags(); boolean isClearTop = (flags & Intent.FLAG_ACTIVITY_CLEAR_TOP) != 0; boolean isSingleTop = (flags & Intent.FLAG_ACTIVITY_SINGLE_TOP) != 0; if (!isClearTop && !isSingleTop) { thiz.finish(); } } }