yasirkula / UnityIonicIntegration

A guide to integrating Unity 3D content into an Ionic app and sending messages between them (for Android & iOS)(tested with Vuforia plugin)
104 stars 32 forks source link

Webview activity is always restarted #17

Closed tehmaestro closed 6 years ago

tehmaestro commented 6 years ago

Hi, I'm trying to integrate your plugin with a plain cordova app. I successfully managed to start the Unity Activity, but once finish is called, the main cordova activity is restarted. Am I missing something? Thank you.

I also do not get the onActivityResult callback.

yasirkula commented 6 years ago

If you are testing your app on an old-ish device, can you also test on a more powerful device? See:

NOTE: On Android platform, if device runs out of memory while running the Unity activity, the Ionic activity is stopped and then automatically restarted by Android OS upon returning to Ionic from Unity. In that case, unfortunately, onReturnedToIonicCallback can not be called.

tehmaestro commented 6 years ago

No, it is a Samsung Galaxy S8. So I just created an empty native android app, super simple app, and the same thing happens. When the Unity Activity is closed, the whole app closes after a couple of seconds. It seems that Unity is destroying not only the currentActivity, but also the parent? Info here: https://medium.com/@davidbeloosesky/embedded-unity-within-android-app-7061f4f473a at step 8

yasirkula commented 6 years ago

As long as you are using IonicComms.FinishActivity instead of Application.Quit, Ionic activity should stay intact. At least that was the case for several test devices that I've used. However, I didn't get a chance to test it on an S8 yet.

tehmaestro commented 6 years ago

I'm actually stopping the Unity Activity from Javascript, added a new stop method. I will return with an answer if I find a fix.

yasirkula commented 6 years ago

If you want to stop the Unity activity from your Ionic code, then I'd suggest the following method:

First, add the following function to IonicComms.cs:

public void ForceQuit( string message )
{
    IonicComms.FinishActivity();
}

Then, call the following function in your Ionic code to stop the Unity activity:

unityARCaller.sendMessage( "ForceQuit", "" );

tehmaestro commented 6 years ago

Hi, so I just realized I was chasing after a solution you already had in place in your plugin. I'm talking about the android:process directive. Unfortunately, this makes my code break while using GoogleSpeechRecognition , something about binder .. I don't know. Anyway, yes, your plugin does work without closing the webview. But the magic happens while using the android:process attribute. Thanks. I don't know what to do about the other issue with the IBinder though ..