【问题标题】:How can I navigate from an activity to another using Navigation Component and removing the first activity from the stack?如何使用导航组件从一个活动导航到另一个活动并从堆栈中删除第一个活动?
【发布时间】:2019-02-22 10:17:24
【问题描述】:
在我的应用程序中,我有两个活动(AuthenticationActivity 和 MainActivity),每个活动都有一个导航图和大量片段。我创建了一个操作来从 AuthenticationActivity 图表的片段导航到 MainActivity,但即使我将 'popTo' 设置为 Authentication 图表 ID,它也不会从堆栈中删除 AuthenticationActivity。
【问题讨论】:
标签:
android
android-architecture-components
android-navigation
【解决方案1】:
在导航方法之后完成身份验证活动:
button2.setOnClickListener {
view.findNavController().navigate(R.id.action_addItemFragment_to_mainActivity)
(activity as AuthenticationActivity).finish()
}