Scheduling recurring task in Android

前端 未结 5 2197
南方客
南方客 2020-11-22 09:12

I\'m designing an app that has a recurring task of sending presence to a dedicated server as long as the app is in foreground.

In my searches across the web I saw a

5条回答
  •  囚心锁ツ
    2020-11-22 09:55

    Quoting the Scheduling Repeating Alarms - Understand the Trade-offs docs:

    A common scenario for triggering an operation outside the lifetime of your app is syncing data with a server. This is a case where you might be tempted to use a repeating alarm. But if you own the server that is hosting your app's data, using Google Cloud Messaging (GCM) in conjunction with sync adapter is a better solution than AlarmManager. A sync adapter gives you all the same scheduling options as AlarmManager, but it offers you significantly more flexibility.

    So, based on this, the best way to schedule a server call is using Google Cloud Messaging (GCM) in conjunction with sync adapter.

提交回复
热议问题