88947

how to resume the application when click app icon launcher in cordova?

Question:

I am developing mobile application with <a href="http://cordova.apache.org" rel="nofollow">cordova</a> phonegap. I am testing it on android platform right now later on ios . My problem is when I have the app running in background, and I click the launcher of this application it is re-initialized. What I want is to just <strong>open the application from the launcher icon and continue running from where it is .</strong> I tried to set the attribute keepRuning in config.xml to <strong>true</strong> but it did not work.

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

This is the config.xml :

<?xml version="1.0" encoding="utf-8" standalone="no"?> <widget xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0" id="com.coolappz.HTML5Application1" version="1.0.0"> <name>HTML5Application1</name> <description>Cordova Application</description> <author email="info@com.coolappz" href="http://www.coolappz.com">user</author> <access origin="*"/> <preference name="fullscreen" value="true"/> <preference name="webviewbounce" value="true"/> <preference name="keepRunning" value="true" /> </widget>

<strong>EDIT:</strong> For more details:

I have a counter that starts from <strong>zero</strong> and increments by 1 every second . The counter resumes to increment in background <strong>if I press home</strong>. The problem is when I press the icon launcher of the application the counter resets from zero because the application is recreated.

I hope this makes the view more clear.

My question :

Can this be handled by cordova configuration or I need a plugin to do so.<br /> Is that possible and how ? Thanks

Answer1:

Update your config.xml for missing preferences. :

<preference name="permissions" value="none"/> <!-- Customize your app and platform with the preference element. --> <preference name="phonegap-version" value="3.3.0" /> <!-- all: current version of PhoneGap --> <preference name="orientation" value="default" /> <!-- all: default means both landscape and portrait are enabled --> <preference name="target-device" value="universal" /> <!-- all: possible values handset, tablet, or universal --> <preference name="fullscreen" value="true" /> <!-- all: hides the status bar at the top of the screen --> <preference name="webviewbounce" value="false" /> <!-- ios: control whether the screen 'bounces' when scrolled beyond the top --> <preference name="prerendered-icon" value="true" /> <!-- ios: if icon is prerendered, iOS will not apply it's gloss to the app's icon on the user's home screen --> <preference name="stay-in-webview" value="false" /> <!-- ios: external links should open in the default browser, 'true' would use the webview the app lives in --> <preference name="ios-statusbarstyle" value="black-opaque" /> <!-- ios: black-translucent will appear black because the PhoneGap webview doesn't go beneath the status bar --> <preference name="detect-data-types" value="true" /> <!-- ios: controls whether data types (such as phone no. and dates) are automatically turned into links by the system --> <preference name="exit-on-suspend" value="false" /> <!-- ios: if set to true, app will terminate when home button is pressed --> <preference name="show-splash-screen-spinner" value="true" /> <!-- ios: if set to false, the spinner won't appear on the splash screen during app loading --> <preference name="auto-hide-splash-screen" value="true" /> <!-- ios: if set to false, the splash screen must be hidden using a JavaScript API --> <preference name="disable-cursor" value="false" /> <!-- blackberry: prevents a mouse-icon/cursor from being displayed on the app --> <preference name="android-minSdkVersion" value="10" /> <!-- android: MIN SDK version supported on the target device. MAX version is blank by default. --> <preference name="android-installLocation" value="auto" /> <!-- android: app install location. 'auto' will choose. 'internalOnly' is device memory. 'preferExternal' is SDCard. --> <preference name="KeyboardDisplayRequiresUserAction " value="false"/>

Answer2:

I tried this solution and it worked for me

Add

android:launchMode="singleInstance"

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

That's it .

Recommend

  • Spark structured steaming from kafka - last message processed again after resume from checkpoint
  • Best practice for storing and searching applicant Résumé or CV file
  • header gets smaller as you scroll - with the scroll
  • Maintaining connection to Firebase realtime database after app is closed if there is data that is st
  • Regex for string splitting not working properly
  • working with proofs involving CmpNat and singletons in Haskell
  • Tracking progress in python list(map(…))
  • Excel named ranges to make incrementing headers and sub headers
  • SQL*Plus : Force it to return an error code
  • Restrict mouse movement over a specified window handle
  • finding symmetric difference/unique elements in multiple arrays in javascript
  • Inno Setup Search for specifc file on a CD, retrieve exact filepath and return value to [Files]-Sect
  • What is wrong with this emulation of CMPXCHG16B instruction?
  • How to make a local git repository that mirrors an upstream repository?
  • Youtube Video Player Fullscreen click event
  • ProgressBar Paint Method?
  • What is wrong in my MVC implementation?
  • Accessing Windows Azure Queues from client side javascript/jquery
  • C: Custom strlen() library function
  • SSRS 2008 - Sorting within a group
  • Small video playback
  • JSON - slashes not escaping
  • Where these are stored?
  • Google Maps api v3 get start and end coordinates of a street
  • Updating both a ConcurrentHashMap and an AtomicInteger safely
  • Django: Count of Group Elements
  • Master page gives error
  • Fetching methods from BroadcastReceiver to update UI
  • Symfony2: How to get request parameter
  • Weird JavaScript statement, what does it mean?
  • Adding custom controls to a full screen movie
  • Apache 2.4 - remove | delete | uninstall
  • GridView Sorting works once only
  • Matrix multiplication with MKL
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • Unit Testing MVC Web Application in Visual Studio and Problem with QTAgent
  • WPF Applying a trigger on binding failure
  • Benchmarking RAM performance - UWP and C#
  • Setting background image for body element in xhtml (for different monitors and resolutions)
  • git trying to push non-existent file … after clearing cache