jump To Activity - Android Activity

Android examples for Activity:Activity Jump

Description

jump To Activity

Demo Code


//package com.java2s;

import android.app.Activity;

import android.content.Context;
import android.content.Intent;

import android.os.Bundle;

public class Main {

    public static void jump(Context old, Class<?> cls, int requestCode,
            Bundle mBundle) {/*from w ww.  j a v  a 2  s  . c o m*/
        jump(old, cls, requestCode, mBundle, false);
    }

    public static void jump(Context old, Class<?> cls, int requestCode,
            Bundle mBundle, boolean clearTop) {
        Intent intent = new Intent();
        intent.setClass(old, cls);
        if (mBundle == null) {
            mBundle = new Bundle();

        }
        Activity oldActivity = (Activity) old;
        mBundle.putString("from", oldActivity.getClass().getSimpleName());
        intent.putExtras(mBundle);

        Activity activity = (Activity) old;
        if (clearTop) {
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            activity.finish();
        }
        activity.startActivityForResult(intent, requestCode);
    }

    public static void jump(Context old, Class<?> cls, int requestCode) {
        jump(old, cls, requestCode, null);
    }
}

Related Tutorials