Pen*_*m10 34 android extras android-intent
这个问题在某种程度上与我想要在startActivityForResult中获得额外内容的问题有关,但现在我面临另一个挑战.
我已订阅接收ProximityAlerts,我已明确构建Intent以包含一些Extras.但是当我得到服务时,额外的东西不存在.
这里的答案是工作代码:
Intent intent = new Intent(this, PlacesProximityHandlerService.class);
intent.setAction("PlacesProximityHandlerService");
intent.putExtra("lat", objPlace.getLat());
intent.putExtra("lon", objPlace.getLon());
intent.putExtra("error_m", objPlace.getError()+ALERT_RANGE_IN_METERS);
PendingIntent sender=PendingIntent.getService(this, 0, intent, 0);
LocationUtils.addProximity(this, objPlace.getLat(), objPlace.getLon(),objPlace.getError()+ALERT_RANGE_IN_METERS, -1, sender);
Run Code Online (Sandbox Code Playgroud)
文档说param PendingIntent to be sent for each location update
ogn*_*ian 42
由于某些未指明的原因,只有在您设置了某些操作时才会传递额外内容,例如setAction("foo").只有在未设置FLAG_ONE_SHOT时,CommonsWare引用的内容仅在获取PendingIntent实例时适用.这可以通过PendingIntent.get ... factory方法中的requestCode参数来修复.尽管文档说它当前没有使用,但在区分PendingIntents时它实际上需要计算.
在您的情况下,除了一些虚拟动作字符串之外,您不需要设置任何其他内容.LocationManagerService重新使用您已订阅接近警报的PendingIntent,并且仅在电话已进入或退出警报范围时才添加标记.
Com*_*are 22
如果您有多个未完成的PendingIntents,您需要确保基础知识的Intents不同之处在于它们的额外内容.否则,Android将继续重复使用PendingIntent您为第一个创建的第一个Intent,首先使用第一个Intent额外的东西.
例如,您可以添加一个独特的操作setAction()- 这不会改变您的Intent路由(因为您指定了组件),但它会使您Intents与众不同.
小智 7
我有这个问题,我找到的解决方案很简单,但我无法解释为什么它有效.
最初我的未决意图看起来像这样:
notificationIntent = new Intent(ctx, FragmentTabsPager.class);
notificationIntent.setData(Uri.parse("content://com.sbs.mobile.workorder.WorkOrder/notes/"));
notificationIntent.putExtra("NOTIFICATION", true);
notificationIntent.putExtra(WorkOrder.WorkOrderColumns.WORKORDERID, submessage);
Run Code Online (Sandbox Code Playgroud)
在创建这样的意图时,单击通知时不会传递额外内容,附加地图在接收活动中将为空.我对初始化notificationIntent的行进行了以下更改:
notificationIntent = new Intent().setClass(ctx, FragmentTabsPager.class);
Run Code Online (Sandbox Code Playgroud)
现在,额外内容填充在接收活动中.再说一次,我无法解释为什么这有效,但它解决了我的问题.
| 归档时间: |
|
| 查看次数: |
12810 次 |
| 最近记录: |