0

I'm building an application for recording the user's route. I have a foreground service where I request the current location every 10 seconds. Because of the fact that LocalBroadcastManager is deprecated, I use Greenrobot's EventBus for sending the coordinates to the activity, where I update a MapView with them.

Because of battery efficiency, I would like to turn the screen off while the user records his route and after the user is ready, when he turns the screen on to sees his actual route on the MapView will terminate the service with a button.

How can I achieve this functionality?

I've searched for a lot of solutions and I found Wave Lock, but it's used for keeping the screen on, the opposite of that what I want.

H.Karatsanov
  • 199
  • 4
  • 16
  • I do not think BroadcastReceiver is deprecated. Where did you get that information from? – Luis Alonso Paulino Flores Apr 25 '20 at 19:21
  • 1
    I'm sorry I edited the post. I was thinking about the LocalBroadcastManager but typed BroadcastReceiver. https://developer.android.com/reference/android/support/v4/content/LocalBroadcastManager – H.Karatsanov Apr 25 '20 at 19:27
  • But both of them are EventBuses, so the information is delivered to the activity. – H.Karatsanov Apr 25 '20 at 19:32
  • Unfortunately, I do not think there is a way to turn the screen off. It was supposed to be possible by using Device Admin permissions via: https://developer.android.com/guide/topics/admin/device-admin, but as it is stated in there, it's being deprecated as of Android 9. – Luis Alonso Paulino Flores Apr 25 '20 at 19:37
  • And when you turn it off by Device Admin permissions, it didn't react as Lock, or? I was searching for a possible explanation, because the service is running, there is no problem with it, it just doesn't update the MapView and the UI. Some explanation would be because the activity enters the other states? – H.Karatsanov Apr 25 '20 at 20:05
  • Hey, sorry for delayed response, I closed this tab by accident. It would do both, turning screen off and locking the device. Regarding your other question, yeah, that is expected, you cannot render anything because of your activity is paused. You might have to store your value in sharedpreferences and once your activity is resumed, show it to keep it up to date and wipe out the value you previously stored. – Luis Alonso Paulino Flores Apr 25 '20 at 21:04
  • No problem. But I was thinking about another approach - Proximity Sensor. It turns off the display, but does it stops the activity? – H.Karatsanov Apr 25 '20 at 21:10

0 Answers0