【发布时间】:2014-08-18 06:14:43
【问题描述】:
我正在创建一个 Intent 并为其添加一个额外的字符串,然后我创建一个 PendingIntent,将其交给警报管理器执行:
String value = "someValue";
Intent intent = new Intent(this, FetchService.class);
intent.putExtra(AppConstants.KEY, value);
alarmIntent = PendingIntent.getService(this, 0, intent, 0);
到目前为止,一切都很好,我用调试器检查了额外的设置。接下来,当在我的服务中调用 onHandleIntent(intent) 时,多余的似乎不再存在
@Override
protected void onHandleIntent(Intent intent) {
// App crashes here
String value = intent.getStringExtra(AppConstants.KEY);
...
}
我似乎无法弄清楚为什么没有多余的东西。我错过了什么吗?
谢谢。
【问题讨论】:
-
如果将
getService的最后一个参数替换为PendingIntent 中定义的FLAG 常量之一(例如FLAG_UPDATE_CURRENT)会发生什么? -
哦,谢谢!做到了。
标签: android android-intent service android-pendingintent extras