Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Unity's function blocked after open other app by Unity then back to Unity under android

First I use Unity to open an webview(by plugin named "uniwebview"). Then I open camera or gallery(by stan's android native plugin) or browser(By Application.OpenURL(url)). After I select picture and back to unity. If adb log like this:

I/Unity   (12779): onPause          //open camera and Unity pause
I/Unity   (12779): windowFocusChanged: true    // after take picture, windowFocusChanged set true and unity resume
I/Unity   (12779): onResume
I/Unity   (12779): OnAndroidRetrieveProductsFinished

Then Unity work fine, but sometimes if adb log like this:

I/Unity   (12779): onPause
I/Unity   (12779): onResume

Unity's function will be blocked.The code I had written in Unity will not work but webview still work fine. I decompilation classes.jar in Unity and found the function windowFocusChanged:

public void windowFocusChanged(final boolean paramBoolean)
  {
    i.Log(4, "windowFocusChanged: " + paramBoolean);
    this.i.a(paramBoolean);
    if ((paramBoolean) && (this.b != null)) {
      reportSoftInputStr(null, 1, false);
    }
    c(new Runnable()
    {
      public final void run()
      {
        UnityPlayer.a(UnityPlayer.this, paramBoolean);
      }
    });
    this.a.a(paramBoolean);
    g();
  }

But I don't know why this function is not work. classes.jar has been obfuscated and hard to read.

like image 233
akishimo Avatar asked Oct 18 '25 07:10

akishimo


2 Answers

I don't know how it works with that plugin we're using "Native Gallery Assist" - https://www.assetstore.unity3d.com/en/#!/content/60922 which reutrns fine back into unity with the image selecgted...

like image 186
Chris Avatar answered Oct 19 '25 23:10

Chris


Unity lost focus when you open other app or interact with other application. If you want to run your functions in background after unity app loses focus then follow the steps below:

  1. In the editor, go to Edit -> Project Settings -> Player. The inspector pane will now change to show the player settings.
  2. Look for the option that says "Run In Background" and check it. If it is disabled and you are done."

Now your functions will run even after unity loses focus.

like image 45
sanjay seju Avatar answered Oct 19 '25 22:10

sanjay seju



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!