How may I prevent Cordova(3.2) App from being kill by Android in background?

android, cordova, cordova-3

Solution

Try adding adding

android:launchMode="singleInstance"

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

This works for me :)

Problem

Hi everyone this is my first question on StackOverflow. I am now making an app with Cordova 3.2 with Telerik AppBulider and I am facing a problem on Android. An app should not be kill when it was put in background. The app works fine if I put it in background and re-open it with the multitask menu. However if I re-open it with the app icon in the drawer, the app will be restart. It only happens on Android (2.3, 4.4, didn't try other). No problem on iOS. I have tried to Google it for solution and most of them bring me to this: ``` <preference name="KeepRunning" value="true"/> ``` which was documented in Cordova 3.2 Documentation, here my config.xml after adding it: ``` <?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 it doesn't help. I have already listen to both pause and resume events. ``` document.addEventListener('deviceready', function() { document.addEventListener('pause', aFunction, false); document.addEventListener('resume', anotherFunction, false); }, false); ``` How can I prevent the app from being restart when I re-open it with the app icon? Thanks :)

Original source

Related problems