- Home /
Launch an activity of Android Studio from Unity App
I am making an App in unity3d which have to launch an activity of another app, and the other app is of Android Studio both apps have to switch for a purpose. I can switch from Android Studio to Unity but I can't switch it from Unity to Android Studio. I have searched a lot and found these three lines of code to help me. the lines of code are below:
AndroidJavaClass javaClass = new AndroidJavaClass("yourApp'sPackageName.theClassYouAreAccessing");
AndroidJavaObject javaObject = javaClass.getStatic<AndroidJavaObject>("NameOfTheStaticMethodYouWantToAccess");
javaObject.Call("AgainTheNameofThatStaticMethod");
--> Second Line can also work like:
AndroidJavaObject object = javaClass.CallStatic<AndroidJavaObject>("NameofTHatStaticMethod");
removing the need of the last line. The first line "AndroidJavaClass" works finely but No matter how I write it the second line "AndroidJavaObject" don't work.
The code of my Android Studio Class is this: package com.example.unityplugin;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
public class javaClass extends Activity {
public static Context context;
public void onCreate(){
context = this;
}
public static void toTheMainActivity() {
Intent intent = new Intent("com.example.usamaakram.anotherone.MainActivity");
context.startActivity(intent);
}
}
the java class I want to access is in the module I made with the name of UnityPlugin and from that class, I want to start the "MainActivity". Also, I have added the classes.jar and UnityPlugin manifest file in "Unity->Plugin->Android->libs" folder,
following this tutorial: link text
Your answer
![](https://koobas.hobune.stream/wayback/20220612175614im_/https://answers.unity.com/themes/thub/images/avi.jpg)