DP5 7.0 - Does adding extras to a pending intent fail?

前端 未结 3 1022
醉酒成梦
醉酒成梦 2021-02-15 17:55

Adding the linked issue on tracker: https://code.google.com/p/android/issues/detail?id=216581&thanks=216581&ts=1468962325

So I installed the DP5 Android 7.0 rele

3条回答
  •  南方客
    南方客 (楼主)
    2021-02-15 18:08

    I've found that wrapping the Parcelable in a Bundle works.

    // When setting up the PendingIntent for the AlarmManager:
    Intent intent = new Intent(context, MyService.class);
    MyParcelable myParcelable = new MyParcelable();
    Bundle b = new Bundle();
    b.putParcelable(EXTRA_MY_PARCELABLE, myParcelable);
    intent.putExtra(EXTRA_BUNDLE, b);
    PendingIntent.getService(0, intent, 0);
    
    // From the Service (or Activity, BroadcastReceiver, etc.):
    Bundle b = intent.getExtra(EXTRA_BUNDLE);
    MyParcelable myParcelable = b.getParcelableExtra(EXTRA_MY_PARCELABLE);
    

    However, I'm not sure how future-proof this approach is. I've commented on the issue on the android bug tracker: https://code.google.com/p/android/issues/detail?id=209422#c11 but I doubt it's going to receive a response since the issue has already been marked closed.

提交回复
热议问题