admin管理员组文章数量:1633183
destination顾名思义是导航的目的地,popUpTo(tag) 跳转到tag,并弹出tag之上的fragment,popUpToInclusive=true会弹出tag,false则不会弹出。
应用场景,Fragment A -> B -> C.
1.正常导航:B导航到C,C返回时回到B。在fragmentB中调用该action
<action
android:id="@+id/action_FragmentB_to_FragmentC"
app:destination="@id/FragmentC"
/>
2.B导航C,C返回时回到A
方法1:在B中调用该action时,虽然会导航到C,但此时Fragment栈中B已经被弹出了(此时C不知道是不是在栈中),所以当C返回时会直接回到A。
<action
android:id="@+id/action_FragmentB_to_FragmentC"
app:destination="@id/FragmentC"
app:popUpTo="@+id/FragmentB"
app:popUpToInclusive="true"
/>
方法2: B到C正常导航,但在C中返回时通过直接导航到A同时设置popUpto为A,popUpToInclusive为false
<action
android:id="@+id/action_FragmentC_to_FragmentA"
app:destination="@id/FragmentA"
app:popUpTo="@+id/FragmentA"
app:popUpToInclusive="false"
/>
3. 在start destination的fragment中调用popBackStack()(一般把start destination的fragment作为启动页,用完就弹出)会导致之后的fragment导航时找不到id的错误。官方是说不能弹出start destination的fragment。不过经过测试,在start destination的fragment的action中通过上述场景2的方法一方法,将popUpTo设为自己,popUpToInclusive为true时能够在栈弹出自己。不过暂时不清楚这种方法是否有别的隐患。
以上是自己使用时的一点心得,有问题欢迎指正
补充一片他人的进阶知识:https://www.jianshu/p/8abff4381585
本文标签: 参数笔记ActionnavigationpopUpToInclusive
版权声明:本文标题:对navigation中action参数的destination,popUpTo,popUpToInclusive的一点笔记 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dianzi/1729143688a1187724.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论