【发布时间】:2017-10-20 21:01:47
【问题描述】:
我编写了一项服务,该服务从基于 CRM 的 Web 服务中获取数据并将其放入手机上的数据库中。现在这个服务必须每 3 小时运行一次,所以它可以在 CRM 和 android 数据库之间同步数据。
现在要让该服务自行运行,我正在使用警报管理器并让 Web 服务自行“启动”。
Intent intent = new Intent(ServiceClass.this, ServiceClass.class);
PendingIntent pintent = PendingIntent.getService(ServiceClass.this, 0, intent, 0);
AlarmManager alarm = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
alarm.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), 10800*1000, pintent);
此服务需要在重启后启动,为此我使用method outlined here..
我只是想知道我是否走在正确的道路上,或者我是否犯了错误,或者是否有更好的方法来做到这一点。我没有太多使用Android,只需要一些指示。谢谢!
【问题讨论】:
-
你用的是什么服务,希望是
IntentService -
@tyczj 我正在使用一个实现服务的类。如果它是一个矫枉过正,我会使用 IntentService
标签: android architecture android-service