Clicking on notification doesn't open mentioned activity

后端 未结 10 1178
感动是毒
感动是毒 2020-12-09 16:26

I am trying to open an Activity when the notification is clicked and below is my code.

Intent intent = new Intent(this.getApplicationContext(),         


        
10条回答
  •  醉话见心
    2020-12-09 16:54

    I had the same problem in my app

    This link helped me: https://developer.android.com/training/notify-user/navigation

    What you need to do is define parent activity for your desired activity in Manifest:

    
        
            
            
        
    
    
    
    

    And then use TaskStackBuilder in onMessageReceived method to create pending intent

    // Create an Intent for the activity you want to start
    Intent resultIntent = new Intent(this, ResultActivity.class);
    // Create the TaskStackBuilder and add the intent, which inflates the back stack
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addNextIntentWithParentStack(resultIntent);
    // Get the PendingIntent containing the entire back stack
    PendingIntent resultPendingIntent =
            stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    // then use this pending intent to build your notification
    

提交回复
热议问题