TaskStackBuilder过渡动画 [英] TaskStackBuilder transition animation

查看:107
本文介绍了TaskStackBuilder过渡动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Android L过渡,其目的是传递 ActivityOptions 捆绑包。
如何使用 TaskStackBuilder 以相同的意图重现动画?

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

这是我目前的工作具有单个 Intent 的方法:

This is my current working method with a single Intent:

startActivity(myIntent, ActivityOptions.makeSceneTransitionAnimation(this).toBundle());

这是我尝试使用 TaskStackBuilder

 TaskStackBuilder builder = TaskStackBuilder.create(this);
 builder.addNextIntentWithParentStack(myIntent);
 builder.startActivities(ActivityOptions.makeSceneTransitionAnimation(this).toBundle());

但是该动画会产生一种奇怪的效果,与单意图版本不同。

But the animation creates a strange effect, not the same one of the "single-intent" version.

我也尝试过:

builder.addNextIntent(myIntent);

而不是:

builder.addNextIntentWithParentStack(myIntent);


推荐答案

TaskStackBuilder内部进行挖掘之后/ code>的实现,问题在于它强制将 Intent.FLAG_ACTIVITY_CLEAR_TASK 添加到堆栈的第一个intent中,这产生了奇怪的效果,因此请使用以下开始堆栈:

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());

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

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.

这篇关于TaskStackBuilder过渡动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆