Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;

public class Main {
    public static void startComponent(Context context, String packageName, String className) {
        Intent intent = new Intent();
        ComponentName component = new ComponentName(packageName, className);
        intent.setComponent(component);
        if (intent != null) {
            context.startActivity(intent);
        }
    }

    public static void startActivity(Activity activity, Class clazz) {
        Intent intent = new Intent(activity, clazz);
        activity.startActivity(intent);
        activity.finish();
    }

    public static void startActivity(Context context, String packageName) {
        Intent intent = context.getPackageManager().getLaunchIntentForPackage(packageName);

        if (intent != null) {
            context.startActivity(intent);
        }
    }
}