TaskStackBuilder and extras for the back stack

后端 未结 3 1743
失恋的感觉
失恋的感觉 2020-12-13 09:17

I\'m trying to use TaskStackBuilder with notifications to create a back stack for the back button to go through. Normal flow of my app:

  1. Activity A is launched
3条回答
  •  不思量自难忘°
    2020-12-13 09:31

    This line:

    sBuilder.addParentStack( ActivityC.class );
    

    adds all parents declared for ActivityC in AndroidManifest.xml in . I don't know what it is, I haven't used it. I doubt you need it.

    This line adds intent to an array:

    sBuilder.addNextIntent(launchIntent);
    

    then the array of intents is used to create PendingIntent, probably with PendingIntent.getActivities, I couldn't find the implementation, which is then started somewhere with Context.startActivities.

    I think you just need to create set of intents, there you can add extras:

    Intent activityA = new Intent(context, ActivityA.class);
    activityA.putExtra(key, valueA);
    Intent activityB = new Intent(context, ActivityB.class);
    activityB.putExtra(key, valueB);
    Intent activityC = new Intent(context, ActivityC.class);
    activityC.putExtra(key, valueC);
    

    and add them to builder:

    sBuilder.addNextIntent(activityA);
    sBuilder.addNextIntent(activityB);
    sBuilder.addNextIntent(activityC);
    pIntent = sBuilder.getPendingIntent( 0, PendingIntent.FLAG_ONE_SHOT );
    

    I haven't tested it, this is only a result of my fast research, I hope someone will correct me if I'm wrong.

提交回复
热议问题