【发布时间】:2014-11-19 07:06:13
【问题描述】:
我通过重复调用BroadcastReceiver 来启动IntentService 以轮询服务器更新,有如下类似的方法:
AlarmManager pollManager;
Intent pollIntent;
PendingIntent pollPendingIntent;
...
pollIntent = new Intent(getActivity(), ActionUpdateReceiver.class);
pollIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
pollIntent.putExtra(RECEIVER, resultReceiver);
pollIntent.putExtra(USER, accountId);
// This is the crux of my question
pollIntent.putExtra(SOMETHING_THAT_UPDATES, updatingThing);
pollPendingIntent = PendingIntent.getBroadcast(getActivity(), ACTION_REQUEST,
pollIntent, PendingIntent.FLAG_CANCEL_CURRENT);
pollManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(),
POLL_INTERVAL, pollPendingIntent);
在轮询服务器和使用ResultReceiver 获取服务器更新方面,上述方法效果很好。但是,我需要向轮询服务提供一些反馈,以便更改我的更新查询。
我应该如何向投票服务提供反馈?如果需要更新查询,我是否只需要取消当前警报并再次设置意图?有没有比取消更好的方法?
【问题讨论】:
-
您的问题不清楚.. 什么是“提供反馈”?什么是轮询服务器?
-
究竟有什么不清楚的地方?轮询服务是由指定的
BroadcastReceiver调用的IntentService。反馈就是反馈。它是更新轮询服务使用的查询的反馈,它取决于重复轮询服务之外的执行。
标签: android broadcastreceiver repeatingalarm android-intentservice