Android - 在活动之间导航时清除历史记录
我的用户不断循环浏览 3 个活动。当用户返回主屏幕时,我需要终止以前的历史记录,这样用户就无法点击后退按钮并最终进入屏幕#2,执行类似操作的好方法是什么? 顺便说一句 - 我正在使用 1.6(API 级别 4)
重申 - 说我不知道或预测引导我到达原始视图的路径。但是一旦我加载它,我想清除引导用户访问该视图的历史记录。在 2.0 中可以覆盖 Activity#onBackPressed 但我需要在 1.6 中类似的东西
I have 3 Activities that my user continuously is looping through. When user is back to the main screen I need to terminate previous history so user cannot hit back button and end up on screen #2, what would be a good way to do something like that?
BTW - I'm using 1.6 (API level 4)
To reiterate - say I don't know or predict the path which leads me to the original view. But once I load it I want to clear history that led user to that view. In 2.0 it's possible with overwriting Activity#onBackPressed but I need something like that in 1.6
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,我假设您有 3 个活动,A、B 和 C。A 是主屏幕,用户将循环浏览这 3 个页面。但是当用户进入A时,onBackPresed事件应该作为退出执行。我说清楚了吗?
在这种情况下,当你尝试从B或C启动A时,你可以将Intent.FLAG_ACTIVITY_CLEAR_TOP添加到Intent中,然后历史堆栈将被清除,堆栈中将只有A。
如果要拦截后退键事件,则不需要重写onBackPressed()。在这个方法可用之前我们总是使用onKeyDown。
Ok, I assume you have 3 activities, A, B and C. A is the main screen and user will loop through these 3 pages. But when user enter A, the onBackPresed event should be performed as exit. Do i make it clear?
In such situation, when you try to start A from B or C, you can add Intent.FLAG_ACTIVITY_CLEAR_TOP to the Intent, then the history stack will be cleared and there will be only A in your stack.
If you want to intercept the back key event, you do not need to override onBackPressed(). We always use onKeyDown before this method is available.
据我所知,如果您想要清晰的活动历史记录,可以通过两种方式进行
(1)。在manifest.xml文件中
您还可以从AndroidManifest.xml文件中实现这一点,只需在您想要的
示例
(2)中添加 android:noHistory="true" 属性即可。在Java代码中,
时添加此标志,
您可以在启动活动Intent.FLAG_ACTIVITY_NO_HISTORY示例
另一个是如果您正在寻找后退按钮刺穿,下面的示例可能会帮助您
如果正在寻找androidapi级别高达 1.6。
希望它能帮助你!
As I know If you want clear history for activity you can do in two ways
(1). In manifest.xml file
You can also implement this from your AndroidManifest.xml file, just adding android:noHistory="true" attribute in those you want
example
(2). In Java code
you can add this flag when you start activity Intent.FLAG_ACTIVITY_NO_HISTORY
example
And the other one is if you are looking for Back Button impalement below example may help you
If looking for android api level upto 1.6.
Hope It will help you!!