gpt4 book ai didi

android - 在多窗口中将焦点更改为第二个应用程序

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:18:57 24 4
gpt4 key购买 nike

我有两个 Android 应用程序在平板电脑上以多窗口模式运行;应用程序 1 和应用程序 2。App1 处于焦点位置,我从 App1 向 App2 发送广播。在那里,我使用 startActivity 在外部打开了一个 web url。但是该 Web URL 在 App1 而不是 App2 中打开,因为 App1 处于焦点。虽然我从 App2 启动了 web url。

我想在 App2 中打开 web url。所以我可能需要先让 App2 关注我的代码?怎么做?

最佳答案

documentation 之后,您可以使用 FLAG_ACTIVITY_LAUNCH_ADJACENT要求 Android 在相邻的焦点窗口中打开给定的 Intent .

例子:

Intent intent = new Intent(getActivity(), Browser.class);
intent.setFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT);
getActivity().startActivity(intent);

文档摘录:

When you launch a new activity, you can hint to the system that the new activity should be displayed adjacent to the current one, if possible. To do this, use the intent flag FLAG_ACTIVITY_LAUNCH_ADJACENT. Passing this flag requests the following behavior:

- If the device is in split-screen mode, the system attempts to create the new activity next to the activity that launched it, so the two activities share the screen. The system is not guaranteed to be able to do this, but it makes the activities adjacent if possible.
- If the device is not in split-screen mode, this flag has no effect.
- If a device is in freeform mode and you are launching a new activity, you can specify the new activity's dimensions and screen location by calling ActivityOptions.setLaunchBounds(). This method has no effect if the device is not in multi-window mode.

Note: If you launch an activity within a task stack, the activity replaces the activity on the screen, inheriting all of its multi-window properties. If you want to launch the new activity as a separate window in multi-window mode, you must launch it in a new task stack.

关于android - 在多窗口中将焦点更改为第二个应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57036997/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com