0

In my app the user can start a tracking service, that uses LocationManager to request location every X seconds.

A user reported that on his device (Galaxy Tab S2), when the device goes it sleep mode, the tracking stops after a few minutes.

I have two questions:

  • is there a way to put my device in sleep mode (for testing)?
  • what would be the impact of using a partial wake lock? On my device, the cpu does not seems to go in sleep anyway, so I guess that there would be no impact, am I right? Or do I need to use AlarmManager, to manually get the location every x seconds (which should imho be an option of the LocationManager, by the way...)?
Tim Autin
  • 6,043
  • 5
  • 46
  • 76
  • as far as i know location manager acquires wakelock itself when it is requested for location update, about location tracking stopping could be related to your service being killed by android system due to some reason. are you handling service stopping properly, like again starting your service or using alarm manager to keep your service up if it is killed by android system – Nishant Pardamwar Aug 28 '16 at 16:59
  • Well my service is sticky, and I already saw it being killed and auto-restarted. Are you sure that LocationManager uses wake locks? From what I found on the web, it doesn't. – Tim Autin Aug 28 '16 at 17:13

1 Answers1

0

1) is there a way to put my device in sleep mode (for testing)?

Yes there is by using PowerManager. Read here. Don't forget to include following permission.

android.permission.DEVICE_POWER

There is an easy way suggested in this SO answer using Device Administration hope that solves you problem.

2) I would suggest you go through this github project to see how to use Partial Wakelock and Alarmmanager efficiently to get the Location. This is a great starting point and you should be able to take lot of good hints of how to proceed.

Community
  • 1
  • 1
Gaurav Sarma
  • 2,248
  • 2
  • 24
  • 45
  • Can you elaborate for #1 please? Are you refering to the goToSleep method stated here : http://stackoverflow.com/questions/9734353/how-to-put-android-to-standby-programmatically? I can't find this method, neither in the doc nor in Android Studio. Thanks for suggesting this project, it may help if I decide to go the AlarmManager option. – Tim Autin Aug 28 '16 at 17:32
  • @TimAutin I had edited the answer for # 1 i hope this is helpful do let me know if it works. Regards – Gaurav Sarma Aug 28 '16 at 17:56
  • Thanks, I'll check it in the end of the week and let you know (I'm working on another project right now)! – Tim Autin Aug 29 '16 at 08:31