草庐IT

pendingintents

全部标签

android - 我应该在 AlarmManager 中使用 PendingIntent.getService() 还是 getBroadcast?

我的应用需要在每天的特定时间从网络上获取一些数据。所以我使用AlarmManager来安排任务并且工作正常。但是在查看各种示例时,似乎有两种方法可以处理待处理Intent时的AlarmManager。当警报响起时,使用PendingIntent.getBroadcast()调用广播接收器,在该接收器内部启动执行实际工作的服务。另一种方法是使用PendingIntent.getService()并在警报响起时直接调用服务。有人可以向我解释这两种方法之间的区别,以便我决定依赖哪一种吗?编辑:还有一个问题是使用getService()时在哪里获取唤醒锁?例如,当使用广播接收器时,我在onRe

android - PendingIntent 对第一个通知正常工作,但对其余通知不正确

protectedvoiddisplayNotification(Stringresponse){Intentintent=newIntent(context,testActivity.class);PendingIntentpendingIntent=PendingIntent.getActivity(context,0,intent,Intent.FLAG_ACTIVITY_NEW_TASK);Notificationnotification=newNotification(R.drawable.icon,"UploadStarted",System.currentTimeMill

android - Intent 和 PendingIntent 的区别

我阅读了一些文章。所有人似乎都在做同样的事情,我想知道启动以下服务有什么区别:Intentintent=newIntent(this,HelloService.class);startService(intent);或以下:Calendarcal=Calendar.getInstance();Intentintent=newIntent(this,MyService.class);PendingIntentpintent=PendingIntent.getService(this,0,intent,0);AlarmManageralarm=(AlarmManager)getSystem

android - PendingIntent 上的 "requestCode"用于什么?

背景:我正在通过AlarmManager使用PendingIntent进行警报。问题:一开始我以为要取消之前的,我必须提供我之前用来启动警报的确切requestCode。但后来我发现我错了,因为cancellationAPI说:RemoveanyalarmswithamatchingIntent.Anyalarm,ofanytype,whoseIntentmatchesthisone(asdefinedbyfilterEquals(Intent)),willbecanceled.查看“filterEquals”,文档说:Determineiftwointentsarethesamefo

android - PendingIntent 不发送 Intent 额外内容

我的MainActicity以Intent启动RefreshService,其中有一个名为boolean的额外称为isNextWeek.我的RefreshService制作了一个Notification,当用户点击它时它会启动我的MainActivity。看起来像这样:Log.d("Refresh","RefreshServicegot:isNextWeek:"+String.valueOf(isNextWeek));IntentnotificationIntent=newIntent(this,MainActivity.class);notificationIntent.putExt