start Activity - Android Activity

Android examples for Activity:Activity Start

Description

start Activity

Demo Code


import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;

public class Main{
    public static final String FRAGMENT_ARGS = "fragment_arg";
    public static final String FRAGMENT_NAME = "fragment_name";
    public static final String FRAGMENT_TAG = "fragment_tag";
    public static void startActivity(Context context, Fragment fragment) {
        startActivity(context, fragment, null);
    }//from w  w w. j  av  a2s  .  com
    public static void startActivity(Context context, Fragment fragment,
            Bundle options) {
        Intent intent = new Intent(context, BaseActivity.class);
        Bundle bundle = new Bundle();
        bundle.putString(FRAGMENT_NAME, fragment.getClass().getName());
        bundle.putString(FRAGMENT_TAG, fragment.getClass().getName());
        bundle.putBundle(FRAGMENT_ARGS, fragment.getArguments());
        intent.putExtras(bundle);

        if (options != null
                && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            context.startActivity(intent, options);
        } else {
            context.startActivity(intent);
        }
    }
    public static void startActivity(Context context, String fragmentName,
            String fragmentTag, Bundle arguments) {
        Intent intent = new Intent(context, BaseActivity.class);
        Bundle bundle = new Bundle();
        bundle.putString(FRAGMENT_NAME, fragmentName);
        bundle.putString(FRAGMENT_TAG, fragmentTag);
        bundle.putBundle(FRAGMENT_ARGS, arguments);
        intent.putExtras(bundle);
        context.startActivity(intent);
    }
}

Related Tutorials