0

I have a very simple Phonegap application that loads an external website:

<script type="text/javascript" src="cordova.js"></script>
<script>
    function onDeviceReady() {
        if (navigator.connection.type == Connection.NONE) {
            navigator.notification.alert('An internet connection is required to continue');
        } else {
            window.location = "http://example.com";
        }
    }
    document.addEventListener("deviceready", onDeviceReady, false);
</script>

When I run it it all works properly and loads the external site. If I switch to a different app and then click the icon to run it (in Android) it switches back to the already running application with no issues.

The problem started occurring when I switched from my testing environment to my production one and switched it to go to an https version. Now, when I click on the icon it restarts the application instead of simply switching back to the application already running.

Is there any way to control whether clicking on the icon reloads the application or simply switches back to the already running application?

EDIT:

Okay, I thought the only difference was changing the "http" to "https", but apparently I also did an upgrade of "phonegap". I tried switching it back to "http" and it's still doing the same wrong thing. Is there any way to control this? I'm currently running 6.5.2 and I think the proper functionality was with 6.5.0 .

EDIT 2:

Alright... It seems that it's somewhat random. I have it running the latest and using "https" and it sometimes reloads and sometimes doesn't.

Tim Tisdall
  • 9,914
  • 3
  • 52
  • 82

1 Answers1

0

Mobile operating system OS's each have different ways of managing memory in apps. The general consensus is that the app should always "save early/often" in case it's killed by the OS to free up memory, etc.

In this case, there may be a way though. Try out the Android Launch Mode preference:

<preference name="AndroidLaunchMode" value="singleInstance" />

I've never used this, so perhaps try out each mode too.

dotNetkow
  • 5,053
  • 4
  • 35
  • 50
  • Yeah, I looked at that. The default is `singleTop`. Both `singleTask` and `singleInstance` seem to indicate they restart where it says 'a new task will always be created and a new instance will be pushed to the task as the root one'. However, I haven't tried it to see exactly what it does. – Tim Tisdall Jul 06 '17 at 12:23
  • Also, I'm aware how Android kills processes, but this seems to be happening immediately (click the icon to first run, then going back to click it immediately restarts). However, when it is restarting, I found killing some other apps seems to encourage it to stay running. – Tim Tisdall Jul 06 '17 at 12:25