本文档概述了如何使用对话框目标会为如何管理后退栈引入独特注意事项。
概述
一个或多个对话框目标只能存在于后退栈的顶部。这是因为当用户导航到不是对话框目标的目标时,NavController
会自动将所有对话框目标从栈顶弹出。这可确保当前目标始终在后退栈上的其他目标上完全可见。
示例
如果后退栈仅由填充导航主机的托管目标组成,并且用户导航到对话框目标,则后退栈可能类似于图 2

如果用户随后导航到另一个对话框目标,则将其添加到后退栈的顶部,如图 3 所示

Dialog
目标。如果用户随后导航到非浮动目标,则在导航到新目标之前,首先会将任何对话框目标从后退栈的顶部弹出,如图 4 所示

Dialog
目标已弹出,并添加了新目标。