PendingIntent sends void to activity












1















I am trying to send data from the notication to my newsdetails class.
but it always retuns null. I tried checking if I actually have data in my variables before sending and it seems I do, So I am trying to figure out why



so this is my MyFirebaseMessageService.class



  Intent intent = new Intent(this, NewsDetails.class);
//intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

String Link = data.get("picture_url");
String Date = data.get("date");
String Title = data.get("title");
String Description = data.get("description");
Log.d("Dateter", Date);
if (Link != null ) {

intent.putExtra("Link",Link);
intent.putExtra("ThumbNail",Link);
}
if (Date != null ) {
intent.putExtra("Date",Date);
}
if (Title != null ) {

intent.putExtra("Title",Title);
}
if (Description !=null ) {
intent.putExtra("Description",Description);
}


NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, "channel_id")
.setContentTitle(notification.getTitle())
.setContentText(notification.getBody())
.setAutoCancel(true)
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
.setContentIntent(pendingIntent)
.setContentInfo(notification.getTitle())
.setLargeIcon(icon)
.setColor(Color.BLUE)
.setLights(Color.BLUE, 1000, 300)
.setDefaults(Notification.DEFAULT_VIBRATE)
.setSmallIcon(R.drawable.logo24x24)
.addAction(R.drawable.logo24x24,"Open",pendingIntent);


and this is part of my Newsdetails.class *(Note that when I use it normally to open an article from my app it will open normally. it only gets Null from the notification. but the data is in MyFirebaseMessageService.class before lunching the intent. is there a different way to get data from pendingitentents? I am using same class for 2 reasons but same variables.



  Bundle bundle = getIntent().getExtras();
Log.d("Title2",bundle.getString("Title"));
date.setText(bundle.getString("Date"));
titletext.setText(bundle.getString("Title"));









share|improve this question



























    1















    I am trying to send data from the notication to my newsdetails class.
    but it always retuns null. I tried checking if I actually have data in my variables before sending and it seems I do, So I am trying to figure out why



    so this is my MyFirebaseMessageService.class



      Intent intent = new Intent(this, NewsDetails.class);
    //intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    String Link = data.get("picture_url");
    String Date = data.get("date");
    String Title = data.get("title");
    String Description = data.get("description");
    Log.d("Dateter", Date);
    if (Link != null ) {

    intent.putExtra("Link",Link);
    intent.putExtra("ThumbNail",Link);
    }
    if (Date != null ) {
    intent.putExtra("Date",Date);
    }
    if (Title != null ) {

    intent.putExtra("Title",Title);
    }
    if (Description !=null ) {
    intent.putExtra("Description",Description);
    }


    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, "channel_id")
    .setContentTitle(notification.getTitle())
    .setContentText(notification.getBody())
    .setAutoCancel(true)
    .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
    .setContentIntent(pendingIntent)
    .setContentInfo(notification.getTitle())
    .setLargeIcon(icon)
    .setColor(Color.BLUE)
    .setLights(Color.BLUE, 1000, 300)
    .setDefaults(Notification.DEFAULT_VIBRATE)
    .setSmallIcon(R.drawable.logo24x24)
    .addAction(R.drawable.logo24x24,"Open",pendingIntent);


    and this is part of my Newsdetails.class *(Note that when I use it normally to open an article from my app it will open normally. it only gets Null from the notification. but the data is in MyFirebaseMessageService.class before lunching the intent. is there a different way to get data from pendingitentents? I am using same class for 2 reasons but same variables.



      Bundle bundle = getIntent().getExtras();
    Log.d("Title2",bundle.getString("Title"));
    date.setText(bundle.getString("Date"));
    titletext.setText(bundle.getString("Title"));









    share|improve this question

























      1












      1








      1








      I am trying to send data from the notication to my newsdetails class.
      but it always retuns null. I tried checking if I actually have data in my variables before sending and it seems I do, So I am trying to figure out why



      so this is my MyFirebaseMessageService.class



        Intent intent = new Intent(this, NewsDetails.class);
      //intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
      PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

      String Link = data.get("picture_url");
      String Date = data.get("date");
      String Title = data.get("title");
      String Description = data.get("description");
      Log.d("Dateter", Date);
      if (Link != null ) {

      intent.putExtra("Link",Link);
      intent.putExtra("ThumbNail",Link);
      }
      if (Date != null ) {
      intent.putExtra("Date",Date);
      }
      if (Title != null ) {

      intent.putExtra("Title",Title);
      }
      if (Description !=null ) {
      intent.putExtra("Description",Description);
      }


      NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, "channel_id")
      .setContentTitle(notification.getTitle())
      .setContentText(notification.getBody())
      .setAutoCancel(true)
      .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
      .setContentIntent(pendingIntent)
      .setContentInfo(notification.getTitle())
      .setLargeIcon(icon)
      .setColor(Color.BLUE)
      .setLights(Color.BLUE, 1000, 300)
      .setDefaults(Notification.DEFAULT_VIBRATE)
      .setSmallIcon(R.drawable.logo24x24)
      .addAction(R.drawable.logo24x24,"Open",pendingIntent);


      and this is part of my Newsdetails.class *(Note that when I use it normally to open an article from my app it will open normally. it only gets Null from the notification. but the data is in MyFirebaseMessageService.class before lunching the intent. is there a different way to get data from pendingitentents? I am using same class for 2 reasons but same variables.



        Bundle bundle = getIntent().getExtras();
      Log.d("Title2",bundle.getString("Title"));
      date.setText(bundle.getString("Date"));
      titletext.setText(bundle.getString("Title"));









      share|improve this question














      I am trying to send data from the notication to my newsdetails class.
      but it always retuns null. I tried checking if I actually have data in my variables before sending and it seems I do, So I am trying to figure out why



      so this is my MyFirebaseMessageService.class



        Intent intent = new Intent(this, NewsDetails.class);
      //intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
      PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

      String Link = data.get("picture_url");
      String Date = data.get("date");
      String Title = data.get("title");
      String Description = data.get("description");
      Log.d("Dateter", Date);
      if (Link != null ) {

      intent.putExtra("Link",Link);
      intent.putExtra("ThumbNail",Link);
      }
      if (Date != null ) {
      intent.putExtra("Date",Date);
      }
      if (Title != null ) {

      intent.putExtra("Title",Title);
      }
      if (Description !=null ) {
      intent.putExtra("Description",Description);
      }


      NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, "channel_id")
      .setContentTitle(notification.getTitle())
      .setContentText(notification.getBody())
      .setAutoCancel(true)
      .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
      .setContentIntent(pendingIntent)
      .setContentInfo(notification.getTitle())
      .setLargeIcon(icon)
      .setColor(Color.BLUE)
      .setLights(Color.BLUE, 1000, 300)
      .setDefaults(Notification.DEFAULT_VIBRATE)
      .setSmallIcon(R.drawable.logo24x24)
      .addAction(R.drawable.logo24x24,"Open",pendingIntent);


      and this is part of my Newsdetails.class *(Note that when I use it normally to open an article from my app it will open normally. it only gets Null from the notification. but the data is in MyFirebaseMessageService.class before lunching the intent. is there a different way to get data from pendingitentents? I am using same class for 2 reasons but same variables.



        Bundle bundle = getIntent().getExtras();
      Log.d("Title2",bundle.getString("Title"));
      date.setText(bundle.getString("Date"));
      titletext.setText(bundle.getString("Title"));






      null android-pendingintent






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 16 '18 at 9:31









      DemeteorDemeteor

      4491617




      4491617
























          1 Answer
          1






          active

          oldest

          votes


















          1














          You must add the "extras" to the Intent before calling PendingIntent.getActivity().



          As you can see, you add the "extras" to the Intent, but after you've gotten a PendingIntent that wraps the Intent. The PendingIntent that you pass to the Notification does not have the "extras" in it.






          share|improve this answer



















          • 1





            Yes that actually makes sense. another newbie mistake, thanks a lot David !

            – Demeteor
            Nov 19 '18 at 10:20












          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53334950%2fpendingintent-sends-void-to-activity%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          You must add the "extras" to the Intent before calling PendingIntent.getActivity().



          As you can see, you add the "extras" to the Intent, but after you've gotten a PendingIntent that wraps the Intent. The PendingIntent that you pass to the Notification does not have the "extras" in it.






          share|improve this answer



















          • 1





            Yes that actually makes sense. another newbie mistake, thanks a lot David !

            – Demeteor
            Nov 19 '18 at 10:20
















          1














          You must add the "extras" to the Intent before calling PendingIntent.getActivity().



          As you can see, you add the "extras" to the Intent, but after you've gotten a PendingIntent that wraps the Intent. The PendingIntent that you pass to the Notification does not have the "extras" in it.






          share|improve this answer



















          • 1





            Yes that actually makes sense. another newbie mistake, thanks a lot David !

            – Demeteor
            Nov 19 '18 at 10:20














          1












          1








          1







          You must add the "extras" to the Intent before calling PendingIntent.getActivity().



          As you can see, you add the "extras" to the Intent, but after you've gotten a PendingIntent that wraps the Intent. The PendingIntent that you pass to the Notification does not have the "extras" in it.






          share|improve this answer













          You must add the "extras" to the Intent before calling PendingIntent.getActivity().



          As you can see, you add the "extras" to the Intent, but after you've gotten a PendingIntent that wraps the Intent. The PendingIntent that you pass to the Notification does not have the "extras" in it.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 17 '18 at 20:57









          David WasserDavid Wasser

          70.2k10143203




          70.2k10143203








          • 1





            Yes that actually makes sense. another newbie mistake, thanks a lot David !

            – Demeteor
            Nov 19 '18 at 10:20














          • 1





            Yes that actually makes sense. another newbie mistake, thanks a lot David !

            – Demeteor
            Nov 19 '18 at 10:20








          1




          1





          Yes that actually makes sense. another newbie mistake, thanks a lot David !

          – Demeteor
          Nov 19 '18 at 10:20





          Yes that actually makes sense. another newbie mistake, thanks a lot David !

          – Demeteor
          Nov 19 '18 at 10:20




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53334950%2fpendingintent-sends-void-to-activity%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Bressuire

          Vorschmack

          Quarantine