EddyVerbruggen / Custom-URL-scheme

:link: Launch your Cordova/PhoneGap app by a Custom URL scheme like mycoolapp://
1.03k stars 365 forks source link

app is relaunched despite being open on android #348

Open Earu opened 10 months ago

Earu commented 10 months ago

So I've skimmed a bit through issues and read the doc, and I couldnt find a definite answer to this. On iOS if my app is already opened it will call the handler keeping the state of the app however on android it re-launches the app and then calls the handler.

This is kinda painful as im using the handler for an oauth process where I need a user to connect to an external webpage opened in the system browser and then redirected to the app using this plugin.

Is there any way to not re-launch the app and call the handler ? Or is this a bug ?

davidhu3141 commented 6 months ago

It might be related to android platform's behavior, which is documented in cordova's platform guide. In your case, it's quite possible that the android system killed your MainActivity when you're opening another browesr, and then restored it afterwards.

If your test device is not that lack of resources, the problem does not happen everytime, is it?

Earu commented 6 months ago

It's been consistent, on both a physical test phone I have and a simulated pixel phone.

Is there any "easy" way to save state and restore it, maybe you know about this ? Because as far as I'm aware I'd have to save stuff to a file and read it again on resume, but the app is quite complex so this would be very tedious.

davidhu3141 commented 6 months ago

To save the states, I just use JS local storage. Does that work for you?

Are there some other inconvenience that you encountered? I understand that at least your JS variables have lost. In my case the handleOpenURL was not called and I have to add

     <config-file target="res/xml/config.xml" parent="/*">
       <feature name="LaunchMyApp">
         <param name="android-package" value="nl.xservices.plugins.LaunchMyApp"/>
+        <param name="onload" value="true" />
       </feature>
     </config-file>

to plugin.xml's android part

Earu commented 6 months ago

Thanks that might help. And yeah my variables are lost, the View/Component/Page that the user had opened are also lost, inputs in forms, etc... All of this makes up to why its very tedious to save the state of the app.

I don't really have any other problem regarding this plugin otherwise.