Move to Next Activity - Android Activity

Android examples for Activity:Activity Jump

Description

Move to Next Activity

Demo Code


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

public class Main {

    private static final int NONE_REQUEST_CODE = -1;

    public static void next(Activity curActivity, Class<?> nextActivity) {
        next(curActivity, nextActivity, null, false, NONE_REQUEST_CODE);
    }//  w  w w  . j  a  va  2s . co  m

    public static void next(Activity curActivity, Class<?> nextActivity,
            int requestCode) {
        next(curActivity, nextActivity, null, false, requestCode);
    }

    public static void next(Activity curActivity, Class<?> nextActivity,
            boolean finishCurrentActivity) {
        next(curActivity, nextActivity, null, finishCurrentActivity,
                NONE_REQUEST_CODE);
    }

    public static void next(Activity curActivity, Class<?> nextActivity,
            Bundle extras) {
        next(curActivity, nextActivity, extras, false, NONE_REQUEST_CODE);
    }

    public static void next(Activity curActivity, Class<?> nextActivity,
            Bundle extras, boolean finishCurrentActivity) {
        next(curActivity, nextActivity, extras, finishCurrentActivity,
                NONE_REQUEST_CODE);
    }

    public static void next(Activity curActivity, Class<?> nextActivity,
            Bundle extras, boolean finishCurrentActivity, int requestCode) {
        Intent intent = new Intent(curActivity, nextActivity);
        if (null != extras) {
            intent.putExtras(extras);
        }
        if (requestCode <= NONE_REQUEST_CODE) {
            curActivity.startActivity(intent);
        } else {
            curActivity.startActivityForResult(intent, requestCode);
        }
        if (finishCurrentActivity) {
            curActivity.finish();
        }
    }

    public static void finish(Activity curActivity) {
        curActivity.finish();
    }
}

Related Tutorials