Android Notification Action is not fired (PendingIntent)

前端 未结 9 1610
盖世英雄少女心
盖世英雄少女心 2020-12-30 02:39

I am trying to add an Notification action item in my app which is a music player. When a stream is started a notification should be triggered and an stop button for the stre

9条回答
  •  庸人自扰
    2020-12-30 03:05

    I ran into this problem today. In my case it was using cached intent extras from a previous instance of the intent as all the parameters for the pendingIntent constructors was same. I found two solutions for this...

    1. Using FLAG_CANCEL_CURRENT as mentioned by Nik.
    2. Passing an unique requestCode to the pendingIntent as follows

      PendingIntent pi = PendingIntent.getService(this, UNIQUE_ID, pi, 0);
      

    In my case, the second method solved the problem as I need to keep the previous notifications alive. May be this will help someone with similar issue.

提交回复
热议问题