用的PendingIntent parcelable额外位置客户端请求的位置更新 [英] Location Client request location updates with parcelable extras in PendingIntent

查看:157
本文介绍了用的PendingIntent parcelable额外位置客户端请求的位置更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用LocationClient用的PendingIntent获得位置更新。

  PendingIntent.getService(背景下,0,新的意图(背景下,OnLocationAvail.class),PendingIntent.FLAG_UPDATE_CURRENT)

以上code正常工作我从关键LocationClient.KEY_LOCATION_CHANGED位置

但是,当我有parcelable数据的额外如下所述,该服务被调用的parcelable数据,但在意向额外LocationClient.KEY_LOCATION_CHANGED关键是始终为空。

 意图callbackIntent =新意图(背景下,OnLocationAvail.class);
callbackIntent.putExtra(SOME_KEY,PARCELABLE_DATA);
PendingIntent.getService(上下文,0,callbackIntent,PendingIntent.FLAG_UPDATE_CURRENT);


解决方案

的问题是,当LocationClient推动通过回调的PendingIntent的更新,过程中不具有ClassLoader的任何信息,因为它是发生在应用程序上下文外并在一个不同的过程。

以下链接帮我缩小问题的范围。
的https://$c$c.google.com/p /安卓/问题/细节?ID = 6822

解决方案:

请求的位置更新时使用黑客捆绑。

 捆绑包=新包();
bundle.putParcelable(com.foo.parcel,some_parcel);
callbackPendingIntent.putExtra(com.foo.bundle,包);

当接收到位置更新

 捆绑oldBundle = intent.getBundleExtra(com.foo.bundle);
some_parcel = oldBundle.getParcelable(com.foo.parcel);

I am using LocationClient with PendingIntent to get location updates.

PendingIntent.getService(context, 0, new Intent(context, OnLocationAvail.class), PendingIntent.FLAG_UPDATE_CURRENT)

The Above code works fine I get the location from the key LocationClient.KEY_LOCATION_CHANGED

But when I have an extras of parcelable data as described below, the service gets called with the parcelable data but the key LocationClient.KEY_LOCATION_CHANGED in the intent extras is always null.

Intent callbackIntent = new Intent(context, OnLocationAvail.class);
callbackIntent.putExtra(SOME_KEY, PARCELABLE_DATA);
PendingIntent.getService(context, 0, callbackIntent, PendingIntent.FLAG_UPDATE_CURRENT);

解决方案

The problem was when the LocationClient pushes an update via the callback PendingIntent, the process doesn't has any information of the ClassLoader since it is happening outside the application context and in a different process.

The following link helped me to narrow down the issue. https://code.google.com/p/android/issues/detail?id=6822

Solution:

Use a hack bundle when requesting for an location update.

Bundle bundle = new Bundle();
bundle.putParcelable("com.foo.parcel", some_parcel);
callbackPendingIntent.putExtra("com.foo.bundle",bundle);

When receiving the location update.

Bundle oldBundle = intent.getBundleExtra("com.foo.bundle");      
some_parcel = oldBundle.getParcelable("com.foo.parcel");

这篇关于用的PendingIntent parcelable额外位置客户端请求的位置更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆