Android - Build a notification, TaskStackBuilder.addParentStack not working

前端 未结 11 2609
说谎
说谎 2020-11-28 06:23

I\'m trying to launch an activity from a notification like the Android docs explain, but when I open the notification and then press the back button, the HomeActivity (paren

11条回答
  •  -上瘾入骨i
    2020-11-28 06:27

    For me the stackBuilder.addParentStack didn't work.

    I end up doing this, hope this could helps you.

        Intent intent = new Intent(context, MatchActivity.class);
    
        TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
        // Adds the back stack for the Intent
        stackBuilder.addNextIntentWithParentStack(new Intent(context, MainActivity.class));
        stackBuilder.addNextIntent(intent);
        PendingIntent pendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    

提交回复
热议问题