我希望我的推送服务在特定间隔之后运行,以便在1小时的时间内将数据推送到服务器。但是它会在1天后停止推送数据,或者有时当应用程序崩溃但服务是海量过程因为它扩展意图-service
public class PushService extends WakefulRepeatableService
{
public PushService() {
super("PushService");
}
@Override
protected void executeBackgroundService(Intent intent) throws Exception {
new SmsLoggerforService(this, dayBeforeYesterday, currentDate, false)
.start();
new CallLoggerforService(this, dayBeforeYesterday, currentDate, false)
.start();
postDataperHour();
}
@Override
protected long getRepeatingInterval() {
return INTERVAL_HOUR;
}
// We can move it to super class using reflection, if Proguard is not being used.
protected Intent getServiceIntent(Context context) {
return new Intent(context,
PushService.class);
}
}
参考本教程https://randling.wordpress.com/2013/12/29/wakeful-and-repeatable-background-service-on-android/