Android: How to repeat a service with AlarmManager every 15 minutes, but only run from 8:00AM to 18:00PM?

后端 未结 2 780
离开以前
离开以前 2020-12-07 23:31

I need to check data update periodly, but the data is only updating during the daytime, so I want this repeating action run only in that time section for saving battery and

2条回答
  •  感情败类
    2020-12-08 00:10

    Follow these easy steps to keep servce alive forever in android device. 1. Call a service by using alarm manager for every 15 minutes. 2. return START_STICKY in onStart method. 3. In on destroy call the alarm manager and restart service by using startService method. 4.(Optional)Repeat the point number 3 in onTaskRemoved method.

提交回复
热议问题