Location Client request location updates with parcelable extras in PendingIntent

佐手、 提交于 2019-11-29 11:27:49

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");
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!