Start Activity by various parameters - Android Activity

Android examples for Activity:Activity Start

Description

Start Activity by various parameters

Demo Code


//package com.java2s;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

public class Main {

    public static void actionStart(Activity activity, Class cls) {
        actionStart(activity, cls, (int[]) null);
    }/*w w  w  .  j a  v  a2 s  . c  o m*/

    public static void actionStart(Activity activity, Class cls,
            int... intentFlags) {
        actionStart(activity, cls, null, intentFlags);
    }

    public static void actionStart(Activity activity, Class cls,
            Bundle bundle) {
        actionStart(activity, cls, bundle, 0);
    }

    public static void actionStart(Activity activity, Class cls,
            Bundle bundle, int... intentFlags) {
        Intent intent = new Intent(activity, cls);
        if (intentFlags != null) {
            for (int i = 0; i < intentFlags.length; i++) {
                if (intentFlags[i] != 0) {
                    if (i == 0) {
                        intent.setFlags(intentFlags[i]);
                    } else {
                        intent.addFlags(intentFlags[i]);
                    }
                }
            }
        }
        if (bundle != null) {
            intent.putExtras(bundle);
        }
        activity.startActivity(intent);
    }
}

Related Tutorials