【问题标题】:Android TaskStackBuilder ugly transitionAndroid TaskStackBuilder 丑陋的过渡
【发布时间】:2016-06-06 20:43:06
【问题描述】:

TaskStackBuilder 到底有什么问题,它在启动新活动时使用了这种丑陋的过渡。:

    TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(this)
            .addParentStack(ActivityB.class)
            .addNextIntent(new Intent(this, ActivityB.class));
    taskStackBuilder.startActivities();

这基本上是谷歌的标准代码,但是如果你运行这段代码,你会在进入 ActivityB 时看到一个超级丑陋的过渡。

我猜是因为它是一个新任务。但我不希望它看起来像这样有什么我可以做的吗?

谢谢!

【问题讨论】:

标签: android taskstackbuilder


【解决方案1】:

在深入了解TaskStackBuilder 的实现之后,问题在于它强制将Intent.FLAG_ACTIVITY_CLEAR_TASK 添加到堆栈中的第一个意图,这使得转换变得丑陋,因此使用以下命令启动堆栈:

Intent[] intents = TaskStackBuilder.create(this)
            .addParentStack(ActivityB.class)
            .addNextIntent(new Intent(this, ActivityB.class))
            .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());

这里的想法是仍然使用TaskStackBuilder 创建您的意图堆栈,然后删除TaskStackBuilder 添加到第一个意图的奇怪Intent.FLAG_ACTIVITY_CLEAR_TASK,然后使用您想要的任何上下文手动启动活动。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-07-18
    • 2016-02-26
    • 2013-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多