Android导航编辑器-完成活动? [英] Android Navigation Editor - Finish Activity?

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

问题描述

我正在首次尝试使用Android的新导航编辑器,但不确定是否缺少此功能,故意遗漏或是否缺少某些内容.我有两个片段,我希望第一个片段能够导航到第二个片段,但是如果要从两个片段中按回去,我都希望活动结束.

I'm trying out Android's new Navigation Editor for the first time and I'm not sure if this is a missing feature, intentional omission, or if I'm missing something. I have two fragments and I want the first fragment to be able to navigate to the second one, but I want the activity to finish if back is pressed from either fragment.

使用当前设置,我可以从mainFragment导航到newFragment.如果我从mainFragment中按回去,则活动结束.我唯一不知道的是从newFragment按下后如何完成活动.我已经尝试了流行行为"设置的所有组合,但没有达到我想要的目的.

With my current setup, I can navigate from mainFragment to newFragment. If I press back from the mainFragment, the activity finishes. The only piece I can't figure out is how to finish the activity when back is pressed from newFragment. I've tried every combination of Pop Behavior settings, but haven't achieved what I'm looking for.

推荐答案

只需在您的操作中将clearTask设置为"true"即可. 但是您的用例违背了导航的概念.

Just set clearTask to "true" on your action. But your use case is going against the concept of the navigation.

https://developer.android.com/topic /libraries/architecture/navigation/navigation-principles#the_app_should_have_a_fixed_starting_destination

应用具有固定的目的地,即用户从启动器启动应用时看到的屏幕. 此目的地也应该是用户在按下后退按钮后返回启动器时看到的最后一个屏幕.

这篇关于Android导航编辑器-完成活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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