【问题标题】:How can I get my intent back from a service that is started by the AlarmManager?如何从 AlarmManager 启动的服务中恢复我的意图?
【发布时间】:2011-06-13 14:59:20
【问题描述】:

我使用警报服务跳转到服务。当服务启动时,我怎样才能找回意图(我想从意图中获取数据)? 我的代码如下

PendingIntent sender=PendingIntent.getService(this, 0, myIntent, 0);
am = (AlarmManager)getSystemService(ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, c.getTimeInMillis(), sender);

如何从服务中取回“myIntent”?没有像 getIntent() 这样的方法 在服务中。我尝试在 onBind(Intent intent) 中使用意图,但这不是我想要的。


我想我解决了这个问题。 PendingIntent 发件人=PendingIntent.getService(this, 0, myIntent, PendingIntent.FLAG_ONE_SHOT);

问题是关于标志的。现在我可以在服务类中恢复我的意图 OnStartCommand(Intent,int,int)

【问题讨论】:

  • 对不起,这完全没有意义。添加该标志应该完全没有改变。这充其量是误导。

标签: android service android-intent alarmmanager android-pendingintent


【解决方案1】:

如何从服务中取回“myIntent”?

它作为参数传递给onStartCommand()(如果这是IntentService,也传递给onHandleIntent())。

【讨论】:

  • 是的,在我将标志从 0 更改为 PendingIntent.FLAG_ONE_SHOT 之前,我未能从 onStartCommand 获取意图。还是谢谢你
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-18
  • 2019-07-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多