如何使用导航组件从一个活动导航到另一个活动,并从堆栈中删除第一个活动? [英] How can I navigate from an activity to another using Navigation Component and removing the first activity from the stack?

查看:60
本文介绍了如何使用导航组件从一个活动导航到另一个活动,并从堆栈中删除第一个活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我有两个活动(AuthenticationActivity和MainActivity),每个活动都有一个导航图和大量片段.我创建了一个动作,可以从AuthenticationActivity的图形片段导航到MainActivity,但是即使将"popTo"设置为Authentication graph id,它也不会从堆栈中删除AuthenticationActivity.

In my app I have two activities (AuthenticationActivity and MainActivity), each one with a nav graph and a big flow of fragments. I've created an action to navigate from a fragment of the AuthenticationActivity's graph to the MainActivity but it does not remove the AuthenticationActivity from the stack even if I set 'popTo' to the Authentication graph id.

推荐答案

在导航方法之后完成身份验证活动:

finish authentication activity after navigate method:

button2.setOnClickListener {
        view.findNavController().navigate(R.id.action_addItemFragment_to_mainActivity)
        (activity as AuthenticationActivity).finish()
    }

这篇关于如何使用导航组件从一个活动导航到另一个活动,并从堆栈中删除第一个活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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