How can I prevent Cordoba (3.2) from killing Android in the background?

Hi everyone, this is my first question on StackOverflow.

Now I am making an application with Cordova 3.2 using Telerik AppBulider, and I ran into a problem on Android.

The application should not be killed when it was placed in the background. The application works great if I put it in the background and re-open it using the multitask menu. However, if I open it again using the application icon in the drawer, the application will restart.

This only happens on Android (2.3, 4.4, have not tried others). No problem with iOS.

I tried Google for a solution, and most of them brought me the following:

<preference name="KeepRunning" value="true"/>

which was documented in Cordoba 3.2 Documentation , here is my config.xml after adding:

<?xml version="1.0" encoding="utf-8"?>
<cordova>
    <access origin="*"/>

    <content src="index.html" />

    <log level="DEBUG"/>
    <preference name="KeepRunning" value="true"/>

    <!-- For projects that target Apache Cordova 3.0.0 only, this <feature></feature> block ensures that button events and App plugin-related functionality will work as expected. -->
    <feature name="App">
        <param name="android-package" value="org.apache.cordova.App" />
    </feature>
</cordova>

But that does not help.

I am already listening to both the suspension and the resumption of events.

document.addEventListener('deviceready', function() {
    document.addEventListener('pause', aFunction, false);
    document.addEventListener('resume', anotherFunction, false);
}, false);

How can I prevent the application from restarting when the application is reopened using the application icon? Thank:)

+4
source share
2 answers

Try to add

Android: launchMode = "SingleInstance"

for the activity tag in AndroidManifest.xml, you can find it in projectName / platform / android / AndroidManifest.xml .

This works for me :)

+2
source

In my experience, "keepRunning" has no effect in Android.

Android System, , , Start-Sticky. , .

, Cordova, Native Android! , , .

:

: keepRunning PhoneGap/ , .

+1

Source: https://habr.com/ru/post/1548027/


All Articles