Location Client request location updates with parcelable extras in PendingIntent

前端 未结 1 1959
花落未央
花落未央 2020-12-19 15:36

I am using LocationClient with PendingIntent to get location updates.

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


        
相关标签:
1条回答
  • 2020-12-19 16:12

    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");
    
    0 讨论(0)
提交回复
热议问题