我已经编写了一项服务,用于从基于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
@tyczj我正在使用实现Service的类。如果这是一个矫枉过正,我会使用IntentService –