0

I want to run a service to send some data to server continuously, but when my watch is sleep mode (when screen is off) app shouldn't stop the service.

  • Give some code? – Liar Feb 28 '18 at 07:33
  • Using broadcast receiver you can detect the on/off of the watch. Then you can start and stop the service accordingly. This is a basic implementation and I suggest you to add more details about the try outs you have done, when you put in a questions. SO community is not that responsive to such generic questions. – Sreedev Feb 28 '18 at 07:36

2 Answers2

0

You should use a WakefulService. This service will keep running in the background. This is called a Wake lock. You can find more about that here. This topic could help you.

Luud van Keulen
  • 1,204
  • 12
  • 38
0

Try!

Start a Service and return START_STICKY in onStartCommand basically it tell android to restart your service when it is killed, but it doesn't guarantee that the service will run indefinitely.

Also use StartForeground() to give your service foreground priority it will keep your service alive as long as it can.

Arnold Brown
  • 1,330
  • 13
  • 28