0

I want to have an Android device continually transmitting its location every few seconds. The location would be transmitted to a website IP so data and other things need to be kept on.

For example, I'm attaching an Android device to a bus to track its current location for a bus route.

The problem is that after a while, the device sleeps and stops transmitting the location. I would rather the solution fit different kinds of devices instead of checking the behavior on one specific device.

Another consideration is that many users will by habit close the device. Some devices like the Asus Nexus 7 will prevent all transmission to networks after a few hours to save battery. So the solution has to consider that the user will force the device to sleep, instead of simply telling the device not to sleep.

keepScreenOn does not seem to be a suitable solution as the screen does not need to be kept on. Wake locks seem to be better suited, but ideally the device would keep the screen off but run in the background.

Another problem is that when the app is minimized or when another app is given the main thread, Android sometimes shuts the background app down and/or ends data/wireless connections to conserve battery. Is there any way to prevent apps from being closed?

Muz
  • 5,866
  • 3
  • 47
  • 65
  • 1
    I think a service and partial wake lock may be your solution. Services have a higher priority than activities and are not usually killed (and can be set to auto-restart if they are). http://stackoverflow.com/questions/6091270/how-can-i-keep-my-android-service-running-when-the-screen-is-turned-off – NigelK Dec 04 '13 at 11:42
  • Services is what you want also make sure you unmarked kill services in background in the settings page – Viswanath Lekshmanan Dec 04 '13 at 11:57
  • I've tried the partial wake lock. My device (Asus Nexus 7) still shuts the app down after a few hours. I might be using it wrong; I set it to release the wakelock in `onStop()`. – Muz Dec 04 '13 at 15:31

0 Answers0