- Home /
Android app crashes when launching a second UnityPlayerActivity from Unity5
I'm trying to launch a second UnityPlayerActivity from Unity5. I saw this very similar question Launch Activity from Unity Activity
Still, it doesn't work with my code in Eclipse and Unity5.
Code in Unity:
AndroidJavaClass ajc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject ajo = ajc.GetStatic<AndroidJavaObject>("currentActivity");
// Accessing the pulse class to call a static method on it.
AndroidJavaClass overrideExample = new AndroidJavaClass("pulse.OverrideExample2");
overrideExample.CallStatic("startOverrideExample", ajo);
Java code:
public class OverrideExample2 extends UnityPlayerActivity {
protected void onCreate(Bundle savedInstanceState) {
// call UnityPlayerActivity.onCreate()
super.onCreate(savedInstanceState);
// print debug message to logcat
Log.d("OverrideExample2", "onCreate called!");
}
public void onBackPressed() {
// instead of calling UnityPlayerActivity.onBackPressed() we just ignore
// the back button event
// super.onBackPressed();
}
public static void startOverrideExample(Activity activity) {
// Creating an intent with the current activity and the activity we wish to start
Intent myIntent = new Intent(activity, OverrideExample2.class);
activity.startActivity(myIntent);
}
}
OverrideExample2 class will be created. But then the app crashes. I'm getting following errors:
06-29 13:53:59.973: D/OverrideExample2(16788): onCreate called!
06-29 13:53:59.978: V/WindowManager(724): Adding window Window{2d9b0e5b u0 com.Company.UHG/pulse.OverrideExample2} at 5 of 11 (after Window{238b26b0 u0 com.Company.UHG/pulse.OverrideExample})
06-29 13:54:00.011: V/WindowManager(724): Adding window Window{1aadb7d1 u0 SurfaceView} at 5 of 12 (before Window{2d9b0e5b u0 com.Company.UHG/pulse.OverrideExample2})
06-29 13:54:00.027: A/libc(16788): Fatal signal 11 (SIGSEGV), code 1, fault addr 0x50 in tid 16845 (UnityMain)
06-29 13:54:00.027: I/libc(16788): Suppressing debuggerd output because prctl(PR_GET_DUMPABLE)==0
06-29 13:54:00.031: I/ActivityManager(724): Displayed com.Company.UHG/pulse.OverrideExample2: +72ms
06-29 13:54:00.060: W/InputDispatcher(724): channel '238b26b0 com.Company.UHG/pulse.OverrideExample (server)' ~ Consumer closed input channel or an error occurred. events=0x9
06-29 13:54:00.060: E/InputDispatcher(724): channel '238b26b0 com.Company.UHG/pulse.OverrideExample (server)' ~ Channel is unrecoverably broken and will be disposed!
06-29 13:54:00.070: W/InputDispatcher(724): channel '2d9b0e5b com.Company.UHG/pulse.OverrideExample2 (server)' ~ Consumer closed input channel or an error occurred. events=0x9
06-29 13:54:00.070: E/InputDispatcher(724): channel '2d9b0e5b com.Company.UHG/pulse.OverrideExample2 (server)' ~ Channel is unrecoverably broken and will be disposed!
06-29 13:54:00.083: I/Zygote(200): Process 16788 exited due to signal (11)
06-29 13:54:00.087: I/WindowState(724): WIN DEATH: Window{238b26b0 u0 com.Company.UHG/pulse.OverrideExample}
06-29 13:54:00.087: W/InputDispatcher(724): Attempted to unregister already unregistered input channel '238b26b0 com.Company.UHG/pulse.OverrideExample (server)'
06-29 13:54:00.088: I/WindowState(724): WIN DEATH: Window{2ddd8dba u0 SurfaceView}
06-29 13:54:00.090: I/WindowState(724): WIN DEATH: Window{2d9b0e5b u0 com.Company.UHG/pulse.OverrideExample2}
06-29 13:54:00.090: W/InputDispatcher(724): Attempted to unregister already unregistered input channel '2d9b0e5b com.Company.UHG/pulse.OverrideExample2 (server)'
06-29 13:54:00.091: I/WindowState(724): WIN DEATH: Window{1aadb7d1 u0 SurfaceView}
06-29 13:54:00.102: I/ActivityManager(724): Process com.Company.UHG (pid 16788) has died
If i try to launch OverrideExample2 class as a MainActivity, then it works. But i want to use multiple Activities in my project.
Please help!
Sorry, i did not manage to solve this issue. I rewrote my code, so that i use only one activity.
Your answer
Follow this Question
Related Questions
My Unity android game cant run on my android 1 Answer
Normal map is not working with Unity 5 when Low-level Native Plugin Interface is used 0 Answers
Problem with obb 0 Answers
How to detect if the Device can run the shader ? 0 Answers
Android application (Unity 5) closes without error a few seconds into game on random devices. 0 Answers