I have exported an Android Unity project to create and Android Studio project (as detailed here: Exporting and running Unity3D project to Android Studio)
While, the project will now run through Android Studio, I am unable to load an Activity which I created after importing the project.
I am wondering is this possible?
I have checked other solution for NullPointerException when calling a new class in android and was unable to see any relating issues, making me question if my approach to this problem is correct
The unity project is a simlple button that will access a method in the UnityPlayerActivity (proved through Log), before attempting to load the new activity AndroidTestActivity, which just contains a TextView.
Code is as follows
Unity C#:
public void Click () {
Debug.Log("Clicked");
AndroidJavaObject jo = new AndroidJavaObject("com.Test.AndroidTest.UnityPlayerActivity");
jo.Call("Created");
}
UnityPlayerActivity.java
public void Created(){
Log.e("tag", "Created");
Intent i = new Intent(this, AndroidTestActivity.class);
this.startActivity(i);
}
LogCat Output:
E/tag: Created
E/Unity: AndroidJavaException: java.lang.NullPointerException: Attempt to
invoke virtual method 'android.app.ActivityThread$ApplicationThread android.app.ActivityThread.getApplicationThread()' on a null object reference
java.lang.NullPointerException: Attempt to invoke virtual method 'android.app.ActivityThread$ApplicationThread android.app.ActivityThread.getApplicationThread()' on a null object reference
at android.app.Activity.startActivityForResult(Activity.java:4400)
at android.app.Activity.startActivityForResult(Activity.java:4358)
at android.app.Activity.startActivity(Activity.java:4682)
at android.app.Activity.startActivity(Activity.java:4650)
at com.Test.AndroidTest.UnityPlayerActivity.Created(UnityPlayerActivity.java:39)
at com.unity3d.player.UnityPlayer.nativeRender(Native Method)
at com.unity3d.player.UnityPlayer.c(Unknown Source)
at com.unity3d.player.UnityPlayer$c$1.handleMessage(Unknown Source)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:154)
I have also ensured that the new activity is declared in the android manifest and it has been imported in UnityPlayerActivity