Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

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);
    }

    /**
     * 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);
    }
}