start Activity And Close Current - Android android.app

Android examples for android.app:Activity Start

Description

start Activity And Close Current

Demo Code

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

public class Main{

    public static void startActivityAndCloseCurrent(Activity root,
            Class<?> activityClass) {
        Intent intent = new Intent(root, activityClass);
        root.startActivity(intent);/*from  ww w .j  a  va2 s .  c om*/
        root.finish();
    }
    public static void startActivity(Activity root, Class<?> activityClass,
            Bundle extras) {
        if (extras == null) {
            throw new RuntimeException(
                    "Bundle is null, use method without bundle.");
        }

        Intent intent = new Intent(root, activityClass);
        intent.putExtras(extras);
        root.startActivity(intent);
    }
    public static void startActivity(Activity root, Class<?> activityClass) {
        Intent intent = new Intent(root, activityClass);
        root.startActivity(intent);
    }

}

Related Tutorials