call when you need to transit form one activity to another - Android Activity

Android examples for Activity:Activity Feature

Description

call when you need to transit form one activity to another

Demo Code


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

public class Main {
    public static void changeActivity(Activity source, Class<?> destination) {
        changeActivity(source, destination, false);
    }//from  w ww.  j  a v  a2 s .  com

    /**
     * call when you need to transit form one activity to another
     * @param shouldFinishContext: true if you want to finish context of the current activity, false otherwise
     */
    public static void changeActivity(Activity source,
            Class<?> destination, Boolean shouldFinishContext) {
        if (shouldFinishContext) {
            source.finish();
        }
        Intent intent = new Intent(source, destination);
        source.startActivity(intent);
    }

    public static void changeActivity(FragmentActivity source,
            Class<?> destination, boolean shouldFinishContext, Bundle bundle) {
        if (shouldFinishContext) {
            source.finish();
        }
        Intent intent = new Intent(source, destination);
        intent.putExtras(bundle);
        source.startActivity(intent);
    }
}

Related Tutorials