I am creating an android app that opens my unity project. My Unity project uses Firebase and Unity multiplayer services, and then closes and goes back to the android activity. For some reason, after the unity activity finishes the code in onActivityResult is executed without a problem and a few seconds later the app crashes. At the moment of the crash the Logcat shows:
unregisterNetworkCallback; CallingUid : 10176, CallingPid : 9103
Sending signal. PID: 9103 SIG: 9
and the app immediately restarts and start running in the background on my device. There are no errors shown, just the app suddenly crashing. This is the relevant code from my main activity:
protected void onCreate(Bundle savedInstanceState) {
...
play_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent(MainActivity.this, com.unity3d.player.UnityPlayerActivity.class);
i.putExtra("name", SharedPreferencesHelper.getValueString(MainActivity.this, "name"));
i.putExtra("sound", SharedPreferencesHelper.getValueBoolean(MainActivity.this, SoundButton.name));
startActivityForResult(i, LAUNCH_SECOND_ACTIVITY);
}
});
}
//I commented out all the code
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
/*if(requestCode == LAUNCH_SECOND_ACTIVITY && resultCode == RESULT_OK)
{
String story = data.getStringExtra("lastStory");
...
Toast.makeText(this, "TEST", Toast.LENGTH_SHORT).show();
}*/
}
From unity I call:
public static void GoBackToAndroid()
{
AndroidJavaClass ajc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject ajo = ajc.GetStatic<AndroidJavaObject>("currentActivity");
ajo.Call("SetDataFromUnity", new object[] { lastStory });
}
and from the unity activity:
public void SetDataFromUnity(String lastStory)
{
Intent returnIntent = new Intent();
/*
returnIntent.putExtra("lastStory", lastStory);
*/
setResult(Activity.RESULT_OK, returnIntent);
finish();
}
The Unity player activity was closing the process on quit, So I ran it on another process (via android:process=":Unity" in the AndroidManifest.xml) and it works