我正在使用带有PendingIntent的LocationClient来获取位置更新。
PendingIntent.getService(context, 0, new Intent(context, OnLocationAvail.class), PendingIntent.FLAG_UPDATE_CURRENT)
以上代码工作正常我从关键LocationClient.KEY_LOCATION_CHANGED获取位置
但是当我有如下所述的额外可分配数据时,使用parcelable数据调用服务,但intent intent中的键LocationClient.KEY_LOCATION_CHANGED始终为null。
Intent callbackIntent = new Intent(context, OnLocationAvail.class);
callbackIntent.putExtra(SOME_KEY, PARCELABLE_DATA);
PendingIntent.getService(context, 0, callbackIntent, PendingIntent.FLAG_UPDATE_CURRENT);
答案 0 :(得分:4)
问题是当LocationClient通过回调PendingIntent推送更新时,该进程没有ClassLoader的任何信息,因为它发生在应用程序上下文之外和不同的进程中。
以下链接帮助我缩小了问题范围。 https://code.google.com/p/android/issues/detail?id=6822
解决方案:
请求更新位置时使用黑客软件包。
Bundle bundle = new Bundle();
bundle.putParcelable("com.foo.parcel", some_parcel);
callbackPendingIntent.putExtra("com.foo.bundle",bundle);
收到位置更新时。
Bundle oldBundle = intent.getBundleExtra("com.foo.bundle");
some_parcel = oldBundle.getParcelable("com.foo.parcel");