private void setMessageEndTrigger(MessageRecommend requireMessage) {
Intent startMessage = new Intent(MESSAGE_START_ACTION);
Bundle bundle = new Bundle();
bundle.putSerializable(MESSAGE, requireMessage);
startMessage.putExtras(bundle);
PendingIntent intent = PendingIntent.getBroadcast(mContext,
MESSAGE_WHAT, startMessage, PendingIntent.FLAG_CANCEL_CURRENT);
if (requireMessage == null) {
LogUtil.debug(TAG + "TimingMessage end is cancel");
mAlarmManager.cancel(intent);
return;
}
long endTime = TimeParseUtil.parseLong(requireMessage.getEndTime());
mAlarmManager.setExact(AlarmManager.RTC_WAKEUP, endTime, intent);
}
private void checkStartMessage(Intent intent) {
MessageRecommend rec = (MessageRecommend) intent.getExtras().get(MESSAGE);
if (!mAreaManager.checkArea(rec.getProvinceName(), rec.getCityName())) {
LogUtil.warning(TAG + "the city is change");
return;
}
if (!mAccountManager.getAccountId().equals(rec.getAccount())) {
LogUtil.warning(TAG + "the Account is change");
return;
}
sendOperatorMessage(rec);
}
- 第一种解决:将bundle使用putExtra方法设置Key和Value,放弃putExtras方法直接put进bundle
private void setMessageStartTrigger(MessageRecommend requireMessage) {
Intent startMessage = new Intent(MESSAGE_START_ACTION);
Bundle bundle = new Bundle();
bundle.putSerializable(MESSAGE, requireMessage);
startMessage.putExtra(MESSAGE, bundle);
PendingIntent intent = PendingIntent.getBroadcast(mContext,
MESSAGE_WHAT, startMessage, PendingIntent.FLAG_CANCEL_CURRENT);
if (requireMessage == null) {
LogUtil.debug(TAG + "TimingMessage start is cancel");
mAlarmManager.cancel(intent);
return;
}
long startTime = TimeParseUtil.parseLong(requireMessage.getStartTime());
LogUtil.debug(TAG + "TimingMessage start time" + startTime);
mAlarmManager.setExact(AlarmManager.RTC_WAKEUP, startTime, intent);
}
- 广播接收时使用先去调用getBundleExtra方法获取bundle,在通过bundle的getSerializable方法获取对象
private void checkStartMessage(Intent intent) {
MessageRecommend rec = (MessageRecommend) intent.
getBundleExtra(MESSAGE).getSerializable(MESSAGE);
if (rec == null) {
LogUtil.debug(TAG + "start time Message is null ");
return;
}
LogUtil.debug(TAG + "start time Message: " + rec.toString());
if (!mAccountManager.getAccountId().equals(rec.getAccount())) {
LogUtil.warning(TAG + "the Account is change");
return;
}
sendOperatorMessage(rec);
}
|