Keep on running an app after the screen auto-locks - Phonegap (Android/iOS)
Asked Answered
T

3

6

I am developing an app that tracks the users movement over GPS (bike riding in particular) and I realized that when the screen auto-locks, the app would stop running (if I'm not mistaken, I'm not completely certain on this).

Is there a way to prevent the phone from auto-locking? Or as an alternative, is there a way (by using Phonegap) to keep on tracking the user's movement after the screen auto-locks (as a background process of some sort)?

Thank you.

Twerp answered 26/9, 2011 at 14:7 Comment(0)
M
3

I'm pretty sure you need to use a Service for this. Services can be started by Activities to run in the background - i.e. you could start the Service in the onPause() method of your Activity.

A service is a component that runs in the background to perform long-running operations or to perform work for remote processes. A service does not provide a user interface. For example, a service might play music in the background while the user is in a different application, or it might fetch data over the network without blocking user interaction with an activity. Another component, such as an activity, can start the service and let it run or bind to it in order to interact with it.

Source: http://developer.android.com/guide/topics/fundamentals.html

Google provides developers with a guide to using Services on the Android developer site. Here's the direct link: http://developer.android.com/guide/topics/fundamentals/services.html

Mishnah answered 26/9, 2011 at 14:14 Comment(1)
Most of us know we can use service to keep the android app running in the backgroud. But how to start a service from Android's Phonegap SDK... dats the issue.... :(Synesthesia
B
1

You can use service for this.

Borborygmus answered 26/9, 2011 at 14:16 Comment(0)
V
0

You can add a plugin that start a service. Add callbacks and methods to the plugin to get notifications or to retrieve information. Plugin is basically a communication layer between Cordova/Phonegap and native.

Vermiform answered 24/3, 2016 at 5:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.