putExtra using pending intent not working

会有一股神秘感。 提交于 2019-11-30 08:06:31

The PendingIntent is reused with the first Intent you provided, that's your problem.

To avoid this, use the flag PendingIntent.FLAG_CANCEL_CURRENT when you call PendingIntent.getActivity() to actually get a new one:

PendingIntent pi = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);

Alternatively, if you just want to update the extras, use the flag PendingIntent.FLAG_UPDATE_CURRENT

The PendingIntent is reused with the first Intent you provided, as it was said by Joffrey. You can try use the flag PendingIntent.FLAG_UPDATE_CURRENT.

PendingIntent pi = PendingIntent.getActivity(this,0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

Maybe you are still using the old intent. try this:

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    //try using this intent

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