Keeping the application running in the background
When we are tracking a device by acquiring geolocation data, it is important to keep an application running in the background so that data can continue to be acquired.
If we are using Android, iOS, or Windows Phone 8, we can keep an application running in the background, even when the device owner is using another application, such as checking email.
The process for each platform is described in the following procedure.
- For Android devices and hybrid applications, to ensure that the application will continue to run in the background use WL.App.setKeepAliveInBackground(true, options). Using this API binds the application to a foreground service. By default, if no options are specified, the application's name and icon are displayed. Tapping on the notification takes the user back to the last activity that made the call to WL.App.setKeepAliveInBackground(true). The notification is present until the app exits, or WL.App.setKeepAliveInBackground(false) is called. For details on using the options to change the text, the icon, or which activity gets called when the user presses on the notification, see the method setKeepAliveInBackground as defined in the WL.App class.
- For Android devices and native applications, you should access the location APIs through a service. For more information about Android services, see the "Services" section on the Android development site at http://developer.android.com/guide/components/services.html.
- For iOS devices, we must set up the info.plist file to indicate to use background location services when enableHighAccuracy=true. To do this, we must set the location string on the UIBackgroundModes key in the info.plist file.
- For Windows Phone 8 devices, replace the DefaultTask details in the WMAppManifest.xml file with: <DefaultTask Name="_default" NavigationPage="MainPage.xml"> <BackgroundExecution> <ExecutionType Name="LocationTracking" /> <BackgroundExecution> </DefaultTask>. See the Windows Phone Development Center web page http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj662935(v=vs.105).aspx for details on running location-tracking apps in the background.
Parent topic: Location services