Android的 - 结算导航Backstack [英] Android - Clearing Navigation Backstack

查看:170
本文介绍了Android的 - 结算导航Backstack的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有4页。

从PAGE_1> page_2> page_3> page_4。

From page_1 > page_2 > page_3 > page_4.

一旦用户达到page_3和点击一个按钮,它定位到page_4。一旦按钮被点击,我要清除所有浏览历史记录,所以当用户回到上page_4,应用程序退出,而不是要回page_3。

Once the user reaches page_3 and clicks a button, it navigates to page_4. Once the button is clicked, I want to clear all the navigation history so when the user goes back on page_4, the app quits rather than going back to page_3.

我试过:

    Intent intent = new Intent(this, page_4.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);
    finish();

但没有任何反应。我还可以回到page_3,page_2等我如何让这个当上page_3此按钮,用户点击,他去page_4和page_4不应该有任何浏览历史?

But nothing happens. I can still go back to page_3, page_2 etc. How do I make it so that when the user clicks on the button on page_3, he goes to page_4 and from page_4 there shouldn't be any navigation history?

推荐答案

我不知道,这些方法会为你的作品。第一种方法是通过添加 FLAG_ACTIVITY_TASK_ON_HOME 当你去从page_3到page_4:

I'm not sure that these methods will works for you. The first method is by adding FLAG_ACTIVITY_TASK_ON_HOME when you go to page_4 from page_3:

Intent intent = new Intent(this, page_4.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_TASK_ON_HOME);
startActivity(intent);

所以一旦你page_4内preSS BACK按钮,把您指向首页的活动(MainActivity)第一,那么你就可以再次preSS BACK按钮从这项活动退出应用程序。

So once you press BACK button within page_4, it directs you to HOME activity (MainActivity) first, then you can press BACK button again to exit the app from this activity.

从文档:

如果设置传递到的意图Context.startActivity(),这个标志将导致新发射任务放在目前的家庭活动任务的顶部(如有一个)。也就是说,pressing从任务回来总是将用户返回到家里,即使这不是他们看到的最后一项活动。这只能在一起使用 FLAG_ACTIVITY_NEW_TASK

If set in an Intent passed to Context.startActivity(), this flag will cause a newly launching task to be placed on top of the current home activity task (if there is one). That is, pressing back from the task will always return the user to home even if that was not the last activity they saw. This can only be used in conjunction with FLAG_ACTIVITY_NEW_TASK.

第二种方式是,将的android:noHistory =真正的清单中的活动范围内。应用此属性,直到PAGE_1 page_4。但这种方法有两个缺点。首先,你的行为是完全没有备用堆栈。第二,你这个属性设置的活动,当您收到来电时被摧毁,一旦你preSS HOME按钮或。我从来没有发现这个问题,所以请CMIIW。

The second way is, set android:noHistory="true" within the activity in manifest. Apply this attribute for page_1 till page_4. But this method has two disadvantages. First, your activity is completely has no back stack. The second, the activities you set with this attribute get destroyed once you press HOME button or when you get an incoming call. I never found this topic, so please CMIIW.

这篇关于Android的 - 结算导航Backstack的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆