我有onle活动和我的项目中的许多片段。我创建了启动画面片段和重定向到 Jmeter 板后3秒。我去 Jmeter 板后,我按下返回按钮,带我回到启动画面。它不应该发生。如何清除重定向后的前一个屏幕。例如,成功付款后,我们将被重定向到一些屏幕,当我们按下返回按钮,它不应该去付款屏幕对吗?。我需要知道如何清除不在活动[Kotlin]中的片段中的回栈。
package spark.ar.assets
import android.content.Intent
import android.os.Bundle
import android.os.Handler
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.findNavController
import spark.ar.assets.databinding.FragmentSplashScreenBinding
class SplashScreen : Fragment() {
private var binding: FragmentSplashScreenBinding?=null
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View {
binding = FragmentSplashScreenBinding.inflate(inflater, container, false)
Handler().postDelayed({
findNavController().navigate(R.id.action_splashScreen_to_dashboard)
}, 3000)
return binding!!.root
}
override fun onDestroyView() {
super.onDestroyView()
binding = null
}
}
这是我的闪屏碎片.重定向后如何清除.
我尝试添加活动?. finish。它关闭了整个应用程序。
Handler().postDelayed({
findNavController().navigate(R.id.action_splashScreen_to_dashboard)
activity?.finish()
}, 3000)
1条答案
按热度按时间zqry0prt1#
若要获得所需内容,必须在nav_graph中正确配置操作。如果在导航组件的设计模式下单击操作,则可以看到“popUpTo”和“popUpToInclusive”部分。在“popUpTo”中,必须设置nav_graph的名称并将“popUpToInclusive”设置为true。若要获得该效果,还必须在导航时使用NavDirections类(它是由导航组件自动生成的)。在您的情况下,它将看起来像这样: