Spifff
Spifff

Reputation: 748

How to resume a cordova app instead of restarting

I have made a default cordova app and adjusted only the index.html file:

<!DOCTYPE html>
<html>
  <body>
    <div id="d"></div>
      <script type="text/javascript">
        var $_d = Math.round(999 * Math.random());
        document.getElementById('d').innerHTML = $_d;        
      </script>
  </body>
</html>

When I build and install the app on my phone, the app will restart every time I restart the app through the short cut or when I click the app in the list of active apps. I notice the app has restarted, since the displayed number has changed. I would hope to prevent the app from restarting, so the number is not changing.

I have tried to accomplish this by adding <preference name="AndroidLaunchMode" value="singleTask"/> to the config.xml file. The AndroidManifext.xml is updated as a result, but it doesn't have the desired effect.

Upvotes: 3

Views: 1379

Answers (1)

Spifff
Spifff

Reputation: 748

Found the solution! Adding "<preference name="AndroidLaunchMode" value="singleTask"/> to the config.xml file does the trick, but you shouldn't have the option "Don't keep activities" checked on your phone, as this would overrule any settings in config.xml or AndroidManifext.xml.

So for anyone who has the same trouble I had: Go to Settings > Developer tools on your android phone and make sure "Don't keep activities" isn't checked.

Upvotes: 1

Related Questions