gpt4 book ai didi

android - 恢复上的透明 Activity 不会显示 android

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:06:00 26 4
gpt4 key购买 nike

我有 3 个 Activity :主页(基本 Activity )与

 <activity
android:launchMode="singleTop"
android:name="com.Home"
android:label="@string/app_name"

android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

其他两个 Activity :Activity1 和 Activity2

主题android:theme="@android:style/Theme.Translucent"可以互相调用,也可以从家里调用。

他们总是回到家 onBackpress()这是覆盖

intent.setClass(this, Home.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);

当activity1被activity2调用时

intent.setClass(this, ACtivity2.class);
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);

它的onResume被调用但是看不到有什么解决办法吗?

我只希望堆栈中有一个 Activity 实例。

要求:Activity1 和 Activity2 应该一旦创建就永远不会被销毁(它们应该总是从历史中调用)直到 Home 被调用。

帮帮我。提前致谢。

Visited this too

最佳答案

我假设问题的发生是因为您正在使用 FLAG_ACTIVITY_CLEAR_TOP 进行家庭 Activity 。

作为,它执行

If there is already an instance of the called activity type present in the stack, then this instance is brought to the foreground instead of creating a new instance. Also, all activities in the stack that reside on top of that instance are cleared from the stack. For example, assuming that the current activity stack is ABCDE, launching an activity of type C will clear activities D and E from the task and result in the stack ABC.

因此,当您调用 Home Activity 时,您的 Activity 1 和 Activity 2 会被清除。

解决方案:

使用 FLAG_ACTIVITY_RESET_TASK_IF_NEEDED 或 FLAG_ACTIVITY_REORDER_TO_FRONT 调用主页 Activity

AS,它执行

This flag has no effect unless the intent creates a new task or brings an existing task to the foreground. In that case, the task is reset, meaning that task affinities are applied (resulting in activities being moved from or to this task) and that, given that FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET is set as well, the task is cleared according that flag’s specification.

关于android - 恢复上的透明 Activity 不会显示 android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15405963/

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