Intent from notification does not have extras

后端 未结 6 652
野性不改
野性不改 2020-12-07 22:38

This seem to be a common problem and I went through all the related questions I could find already: Activity isn't picking up new intent, Why extra data (integer) is not

6条回答
  •  Happy的楠姐
    2020-12-07 22:42

    You can send extras in intent following way

    PendingIntent contentIntent ;
    Intent intent = new Intent(this,TestActivity.class);
    intent.putExtra("extra","Test");
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    
    stackBuilder.addParentStack(ArticleDetailedActivity.class);
    
    contentIntent = stackBuilder.getPendingIntent(0,PendingIntent.FLAG_UPDATE_CURRENT);
    

    To Get Intent extra value in Test Activity class you need to write following code :

    Intent intent = getIntent();
     String extra = intent.getStringExtra("extra") ;
    

提交回复
热议问题