TaskStackBuilder transition animation

后端 未结 2 1385
一生所求
一生所求 2021-02-06 20:41

I\'m using Android L transitions passing an ActivityOptions bundle in intent. How can I reproduce the animation on the same intent with TaskStackBuilder

2条回答
  •  天涯浪人
    2021-02-06 20:59

    After digging inside TaskStackBuilder's implementation, the problem is that it forces adding Intent.FLAG_ACTIVITY_CLEAR_TASK to the 1st intent in the stack, which makes that strange effect, so use the following to start the stack:

    Intent[] intents = TaskStackBuilder.create(this)
                         .addNextIntentWithParentStack(myIntent)
                         .getIntents();
    if (intents.length > 0) {
        intents[0].setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);// Or any other flags you want, but not the `.._CLEAR_..` one
    }
    // `this` inside current activity, or you can use App's context
    this.startActivities(intents, ActivityOptions.makeSceneTransitionAnimation(this).toBundle());
    

    The idea here is to still use the TaskStackBuilder for creating your intents' stack, then remove the weird Intent.FLAG_ACTIVITY_CLEAR_TASK that the TaskStackBuilder adds to the 1st intent, then start the activities manually using any Context you want.

提交回复
热议问题