4 Replies Latest reply on Aug 24, 2016 10:37 AM by brunos16848183

    [Android] Keep app running on "screen lock"




      I hope you are able to help me. And sorry for my bad English.


      I needed to know which way to run an app when the "screen lock" is enabled. I get that app run javascript in background mode, but when the "screen lock" is activated, the app stops running javascript code after 5 seconds.


      I've looked on Google and forum, but I could not find anything that works


      Already tried:

      • Keeprunning -> true (on config file)
      • cordova-plugin-powermanagement
      • cordova-plugin-insomnia
      • de.appplant.cordova.plugin.background-mode


      The app would always run a 'setInterval' to communicate with the server.


      Can anyone help me? Thank you very much!


      Platform: Android (Huawei P8 Lite)

        • 1. Re: [Android] Keep app running on "screen lock"
          kerrishotts Adobe Employee

          What's your use-case for doing this? This would end up draining the battery pretty quickly.

          • 2. Re: [Android] Keep app running on "screen lock"
            brunos16848183 Level 1

            The app needs to track the user's location constantly, even in the background. I know it will drain a lot of battery, but it has to be like this.


            For background geolocation, I use the plugin:



            But the app needs to get some server information, and for this I use a setInterval to make an ajax request.


            For running code in the background, I use the plugin:



            The problem is that the app quits when the lock screen appears ... and I could not even find a solution.


            Maybe memory leak? Still, there will be a way around this?


            I am very grateful for the help.

            • 3. Re: [Android] Keep app running on "screen lock"
              kerrishotts Adobe Employee

              Is this an enterprise app, or is it destined for the Play store?


              Also -- why does it have to be this way? I'm assuming a client requirement here, but this in no way guarantees the user's location -- just the location of the device. And if this is going to the play store, that's incredibly anti-user & anti-privacy.


              As for quitting when the device is locked... I don't know. Check the device console (adb logcat) and see if there's any error messages being generated at around the same time.

              • 4. Re: [Android] Keep app running on "screen lock"
                brunos16848183 Level 1

                Thanks for your help!


                The app is for the app store, it's a geolocation based game. The location of the device is enough.


                Yes, knowing the constant location will not be ideal, but the game idea is to know where the other players are. And players will be alerted about it.


                About the app exit in the background, I think that is the smartphone memory.

                But I will check and give feedback here.



                Again, I appreciate the help.