Tips on restarting the application after clicking the app icon launcher in Cordova

I'm currently working on a mobile application using PhoneGap with Cordova, testing it on android before moving onto iOS. My issue is that when the app is running in the background and I click on the launcher icon to open it again, it restarts instead of continuing from where it left off. I tried setting the attribute keepRunning to true in the config.xml file, but it didn't solve the problem.

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

This is my 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="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ec85828a83ac8f8383808d9c9c96">[email protected]</a>" 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>

EDIT: For more details:

I have a counter that starts at zero and increases by 1 every second. The counter continues to increment in the background if I press home. However, when I tap the launcher icon, the counter resets to zero because the app is being recreated.

I hope this clarifies the situation.

My question :

Can this issue be resolved through Cordova configuration or do I need a plugin to address it?
Is there a solution available, and if so, how can I implement it? Thanks

Answer №1

Make sure to update your config.xml file with the necessary preferences:

    <preference name="permissions"                value="none"/>
     <!-- Don't forget to customize your app and platform using the preference element. -->
    <preference name="phonegap-version"           value="3.3.0" />    <!-- Latest version of PhoneGap -->
    <preference name="orientation"                value="default" />        <!-- Set orientations for both landscape and portrait -->
    <preference name="target-device"              value="universal" />      <!-- Choose between handset, tablet, or universal devices -->
    <preference name="fullscreen"                 value="true" />           <!-- Hide status bar at the top of the screen -->
   <preference name="webviewbounce"              value="false" />           <!-- Control screen bouncing on iOS -->
   <preference name="prerendered-icon"           value="true" />           <!-- Prevent iOS from adding gloss to app icon -->
   <preference name="stay-in-webview"            value="false" />          <!-- Decide if external links should open in default browser or within app webview -->
   <preference name="ios-statusbarstyle"         value="black-opaque" />   <!-- Ensure status bar doesn't overlay content on iOS -->
   <preference name="detect-data-types"          value="true" />           <!-- Automatically detect data types like phone numbers and dates on iOS -->
   <preference name="exit-on-suspend"            value="false" />          <!-- Determine whether app terminates when home button is pressed on iOS -->
   <preference name="show-splash-screen-spinner" value="true" />           <!-- Show spinner during app loading on iOS splash screen -->
   <preference name="auto-hide-splash-screen"    value="true" />           <!-- Automatically hide splash screen on iOS -->
   <preference name="disable-cursor"             value="false" />          <!-- Disable mouse cursor display on BlackBerry apps -->
   <preference name="android-minSdkVersion"      value="10" />              <!-- Specify minimum SDK version for Android devices -->
   <preference name="android-installLocation"    value="auto" />           <!-- Choose app installation location on Android devices -->
   <preference name="KeyboardDisplayRequiresUserAction " value="false"/>

Answer №2

After experimenting with different approaches, I finally found success with the following solution:

Include the following line in the activity tag of your AndroidManifest.xml file:

     android:launchMode="singleInstance"

You can locate the AndroidManifest.xml file at projectName/platforms/android/AndroidManifest.xml.

And that's all there is to it!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Showing email addresses and names from the address book on a table view during text field editing in the iOS platform

I am encountering an issue with my application. I have a text field where users can input text, and below that, there is a table view. The functionality is such that when the user starts typing in the text field, it searches the address book for matching n ...

Should func be called upon completion of the action?

First of all, thank you for taking the time to help me out. I'm facing a rather simple problem that I can't seem to solve on my own. I am currently working on developing a Tower Defense game and I want to implement a feature where the life bar o ...

Utilize AngularJS ng-repeat directive to refine JSON objects

I'm working on an angular js controller with a json array that organizes countries by continents. Each continent consists of its own array of countries. //CONTROLLER app.controller('CountryController', function(){ this.continents = ...

What is the reason for the lack of impact from the toLocaleString() method?

Is it possible to utilize the toLocaleString() method in NativeScript? Take a look at this example on {N} Playground <script> export default { data() { return { trDate: new Date(1579180347000).toLocaleString( ...

Can I secure my Android applications with Google password authentication? (Using OpenID for native apps)

Scenario: User opens the application User inputs their Google password The application grants access if the entered Google password is correct. I am looking to streamline the login process for my users by avoiding additional password registrations ...

Overlap one element entirely with another

Currently, I am working on a way for an element called overlayElement to completely cover another element known as originalElement. The overlayElement is an iFrame, but that detail may not be significant in this scenario. My goal is to ensure that the over ...

The masonry plugin overlays images on top of each other

I have gone through similar questions but haven't found anything that applies to my specific case. Following an ajax call, I am adding li elements to a ul $.ajax({ url: 'do_load_gallery.php?load=all' }).done(function(result) { ...

There seems to be an issue with rendering or redirecting in Jade files, the routes folder, and server/app.js

//routes/meal.js var express = require('express'); var router = express.Router(); var app = express(); /* GET users listing. */ router.get('/meal', function(req, res, next) { res.render('/home/noah/Desktop/gadfit/views/meal.jad ...

Open an iOS application using Appium with launch parameters and/or environmental settings

Issue: Upon testing the app's launch, it has been observed that the app retrieves the IP address of the current user to determine their country of origin. Depending on this information, the backend URL is adjusted accordingly. I need a way to simulat ...

Establishing SAPUI5 Odata Connection with Server

Hello, I have a question. Is it possible to access OData data without using a cloud connector? For example, can I retrieve the data directly from a URL like https://serverip:port/sap/opu/odata/sap/? When I try accessing it through the browser, I am able to ...

jQuery's callback handling often reverses the statement I just made

My current project involves using AJAX with jQuery to send a get request. Once the request is successful, I insert the response into a specific div: $.get("content.php", function(result) { $('#content').html(result); The content I'm fetc ...

Tips for retrieving the value of a table cell when the checkbox in the corresponding row is selected

Within my project, I am utilizing a table. The html code I am using is as follows: <table id="assTB" border="1px" cellspacing="0"> <colgroup> <col style="width:15%"> <col style="width:15%"> <col sty ...

Avoid triggering the API with rapid successive clicks

My project involves creating an Instagram-clone with like and dislike buttons. When a user is logged in and hasn't liked or disliked a post yet, both buttons appear as black. If the user likes a post, the like button turns blue, and if they click disl ...

Retrieving Extensive Information for Display on Data Table - Incorporating ReactJS

I am currently facing a challenge with my web page that contains a table populated with 20,000 rows of data fetched from my database. To enhance performance, I have stored this large dataset in localStorage. However, when users navigate to this particular ...

Decoding with Gson: Say No to Wrapper Classes

Working on deserializing the JSON data provided using Gson in Kotlin. { "things": [ { "name": "Thing1" }, { "name": "Thing2" } } } Currently, there are two classes involved in deserialization; ThingWrapper - Contains a p ...

The function e.preventDefault() appears to be ineffective when applied to both the submit button and anchor tag within an

In my ASP.Net Core MVC App View <form> <div class="container"> <div class="row"> <div class="col-md-offset-2 col-md-4"> <div class="form-group"> <input type="text" class="form-contr ...

What is the best way to loop through a group of WebElements, and only log the results that contain a specific substring?

In my test case, I'm utilizing Mocha to handle the scenario. The test appears to be passing successfully, however, no logs are being printed... it('Is 'Mooooooo!!!! I2MaC0W' a Substring in Results?', function() { this.timeout(50 ...

Click event doesn't trigger the 'else if' statement in jQuery

Having trouble with a button click issue. In the following code, when the button is clicked, it checks if the text on the button is "day". If so, it changes the background-color of the body to red and updates the button text to "night". I am struggling wit ...

Tips for identifying the name property within an array of Objects

I'm currently working on extracting values from an array of objects based on their IDs, but I've hit a roadblock. The issue lies in the fact that I have this array of objects and I'm unsure about how to properly iterate through them. While I ...

Creating a distinct header value for every $http request

I've been assigned the task of adding a unique ID for each request to all HTTP requests made by our AngularJS application for logging purposes. While this is more crucial for API calls, I'm currently working on implementing it for all kinds of re ...