在Android 6.0上使用chrome时,我可以长按链接,选择“在新标签页中打开”并将其打开到当前任务后面的另一个任务中。
现在我需要做一些熟悉的事情,但是我无法找到如何让我的活动在一个新任务中开始,让任务从花哨的动画开始在当前任务的后面。
我找到了
public static final int ANIM_LAUNCH_TASK_BEHIND = 7;
,并且有一个javadoc:
/**
* If set along with Intent.FLAG_ACTIVITY_NEW_DOCUMENT then the task being launched will not be
* presented to the user but will instead be only available through the recents task list.
* In addition, the new task wil be affiliated with the launching activity's task.
* Affiliated tasks are grouped together in the recents task list.
*
* <p>This behavior is not supported for activities with {@link
* android.R.styleable#AndroidManifestActivity_launchMode launchMode} values of
* <code>singleInstance</code> or <code>singleTask</code>.
*/
public static ActivityOptions makeTaskLaunchBehind() {
final ActivityOptions opts = new ActivityOptions();
opts.mAnimationType = ANIM_LAUNCH_TASK_BEHIND;
return opts;
}
所以似乎android支持这个功能,但我无法找到如何使用它。有没有人做过类似的事情?如何在新任务中打开新活动并让它在当前任务后面发生?
答案 0 :(得分:0)
好吧,在源代码中进行一些搜索后,我发现动画类型可以通过startActivity中传递的选项指定...但是请求此功能的键和值似乎不公开,因为我无法访问它们直。但是,毕竟,我可以使用以下代码来请求此功能:
Intent intent = new Intent(MainActivity.this, TestActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
Bundle bundle = new Bundle();
bundle.putInt("android:activity.animType", 7);
startActivity(intent, bundle);
现在我想知道是否有更好,更标准的方式来请求此功能?使用文字字符串而不是某个类的常量字段看起来很危险。