Why do we use the TaskStackBuilder?

后端 未结 6 592
难免孤独
难免孤独 2020-12-24 01:12

Why do we use the TaskStackBuilder when creating a notification? I do not get the logic behind it.

Can someone please explain.

public v         


        
6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-24 01:53

    The other answers explained it nicely: you use a pending intent to send a user into a detail activity, then you want them to use the back button to go back to the main activity. An alternative way to set this is

    Intent detailIntentForToday = new Intent(context, DetailActivity.class);
    TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(context);
    taskStackBuilder.addNextIntentWithParentStack(detailIntentForToday);
    PendingIntent resultPendingIntent = taskStackBuilder
        .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    resultPendingIntent.send();
    

    For this, you also need to set

    android:parentActivityName=".MainActivity"
    

    for the DetailActivity in AndroidManifest.xml.

提交回复
热议问题