android:noHistory="true" 是如何工作的?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11836080/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 08:59:29  来源:igfitidea点击:

How does android:noHistory="true" work?

android

提问by M Jesse

Lets say I have a base activity with a menu, when I click on menu item A, it goes to activity A. I open the menu again, and go to B. From B I go back to A, and back and fourth like this for a while.

假设我有一个带有菜单的基本活动,当我单击菜单项 A 时,它会转到活动 A。我再次打开菜单,然后转到 B。从 BI 返回到 A,然后返回到第四个一会儿。

So the stack would be A, B, A, B, A, B, .... And when I hit the back button, it goes backwards through the stack as expected.

所以堆栈将是 A, B, A, B, A, B, .... 当我按下后退按钮时,它按预期向后通过堆栈。

However lets say I don't want this functionality, so I add to my manifest, android:noHistory="true". So when I hit the back button it exits the application instead of going though the stack.

但是可以说我不想要这个功能,所以我添加到我的清单中,android:noHistory="true". 因此,当我点击后退按钮时,它会退出应用程序而不是通过堆栈。

Now the illusion makes it seem, lets say if I'm in activity A, I use the menu and go to activity B, the stack would just be B, because I can't go back to A.

现在这种错觉看起来像,假设我在活动 A 中,我使用菜单并转到活动 B,堆栈将只是 B,因为我无法返回 A。

But, when using noHistory="true", does the true stack of A, B, A, B, A, B exist? Rather, is every call to an activity by using the menu instantiating a new copy of that activity, but the user can't see it? Would this be causing resource issues?

但是,当使用 时noHistory="true",A、B、A、B、A、B 的真实堆栈是否存在?更确切地说,是不是每次使用菜单调用活动都会实例化该活动的新副本,但用户看不到它?这会导致资源问题吗?

Or when noHistory="false", does the back button just call something like startAcitvity(intent)again or is it going through each new copy that was instantiated?

或者什么时候noHistory="false",后退按钮是startAcitvity(intent)再次调用类似的东西还是遍历每个被实例化的新副本?

I'm concerned with resource issues and not slowing down a users android device.

我担心资源问题,而不是减慢用户 android 设备的速度。

回答by slayton

From the docsabout noHistory:

文档有关noHistory

A value of "true" means that the activity will not leave a historical trace. It will not remain in the activity stack for the task, so the user will not be able to return to it.

“true”值意味着活动不会留下历史痕迹。它不会保留在任务的活动堆栈中,因此用户将无法返回到它。

Regarding your question:

关于你的问题:

does the true stack of A, B, A, B, A, B exist?

A、B、A、B、A、B 的真实堆栈是否存在?

The docs would indicate no.

文档会表明没有。

I'm concerned with resource issues and not slowing down a users android device.

我担心资源问题,而不是减慢用户 android 设备的速度。

You really don't need to worry about this. The OS should handle the cleanup of activities when memory is getting low. Its more likely that poor use of bitmaps or logic in your activities will result in performance slowdowns.

你真的不需要担心这个。当内存变低时,操作系统应该处理活动的清理工作。在您的活动中对位图或逻辑的不当使用更有可能导致性能下降。

回答by Raghav Bhatia

android:noHistory=“true” works :-

android:noHistory="true" 有效:-

Let suppose you have opened "your app".

假设您已打开“您的应用程序”。

You are on homepage Activity now,

您现在在主页活动,

After it you go to the another(second) activity.Here from second activity you press the home button of mobile device or open the some other application.

之后,您转到另一个(第二个)活动。从第二个活动中,您按下移动设备的主页按钮或打开其他应用程序。

Now again if you open "your app" it will go to the homepage of app instead of going to the activity which one you left the app(i.e.second activity).

现在,如果您再次打开“您的应用程序”,它将转到应用程序的主页,而不是转到您离开应用程序的活动(即第二个活动)。

回答by Ashutosh

I had few fragments in my app and it seemed difficult to get out to the home screen by pressing back button without entering Launcher Activity of my app. I used android:noHistory="true" in the manifest of the launcher Activity of my app and the problem gets solved now.

我的应用程序中几乎没有片段,并且在不进入我的应用程序的启动器活动的情况下按后退按钮似乎很难进入主屏幕。我在我的应用程序的启动器活动的清单中使用了 android:noHistory="true" 并且问题现在得到了解决。