如何从 AlarmManager 启动的服务获取我的意图?
我使用警报服务跳转到某个服务。当服务启动时,我可以如何获取意图(我想从意图中获取数据)? 我的代码如下
PendingIntent sender=PendingIntent.getService(this, 0, myIntent, 0);
am = (AlarmManager)getSystemService(ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, c.getTimeInMillis(), sender);
如何从服务中获取“myIntent”?没有像 getIntent() 这样的方法 在服务中。我尝试在onBind(Intentintent)中使用意图,但这不是我想要的。
我想我已经解决了这个问题。 PendingIntent 发送者=PendingIntent.getService(this, 0, myIntent, PendingIntent.FLAG_ONE_SHOT);
问题出在旗帜上。现在我可以在服务类中恢复我的意图 OnStartCommand(意图,int,int)
I use an alarm service to jump to a service. when the service starts, hwo can I get the intent back(I want to get data from the intent)?
My code is as follows
PendingIntent sender=PendingIntent.getService(this, 0, myIntent, 0);
am = (AlarmManager)getSystemService(ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, c.getTimeInMillis(), sender);
How do I get "myIntent" back from the service? there's no method such like getIntent()
in service. I tried to use the intent in onBind(Intent intent), but it is not what I want.
I think I got this porblem solved.
PendingIntent sender=PendingIntent.getService(this, 0, myIntent,
PendingIntent.FLAG_ONE_SHOT);
the problem is about the flag. now I can get my intent back at the service class
OnStartCommand(Intent,int,int)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它作为参数传递给
onStartCommand()
(如果这是一个IntentService
,也传递给onHandleIntent()
)。It is passed as a parameter to
onStartCommand()
(and, if this is anIntentService
, also toonHandleIntent()
).