Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

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

public class Main {
    /**
     * This method is used for opening any activity from another application. In this case we must ensure that
     * the desired activity is set to "exported". Such as in manifest file:
     *
     * <activity
     *     android:name=".activity.DesiredActivity"
     *     android:exported="true"
     *     android:screenOrientation="portrait">
     * </activity>
     *
     *
     *
     * @param context                                The context of the activity.
     * @param desiredPackageName                     The package name of the desired or another application.
     * @param desiredActivityNameWithFullPackageName The full path of the activity. Such as : com.example.activity.DesiredActivity
     */
    public static void launchActivityFromAnotherApp(Context context, String desiredPackageName,
            String desiredActivityNameWithFullPackageName) {
        Intent intent = new Intent();
        intent.setComponent(new ComponentName(desiredPackageName, desiredActivityNameWithFullPackageName));
        context.startActivity(intent);
    }
}