restart Activity for HONEYCOMB or older version - Android android.app

Android examples for android.app:Activity Start

Description

restart Activity for HONEYCOMB or older version

Demo Code

import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Intent;
import android.os.Build;

public class Main{

    /**/*from  w w w  .j  a va 2 s  .c o m*/
     * Restart the Activity
     *
     * @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);
        }
    }

}

Related Tutorials