-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
清空back stack后跳转 #15
Comments
出现了一样的报错,需求是在启动一个activity时 动态判断 设置 setStartDestination(),如果在oncreate就报上面的错,如果是onstart()就同过,个人理解是初始化未完成就开始清理栈。问题是之前的项目没有出现。 override fun onCreate(savedInstanceState: Bundle?) {
// R.id.homeFragment
|
兄弟 你需要换种写法来获取NavController |
具体怎么写?麻烦了 |
class MainActivity : AppCompatActivity() {
} |
换了Navigation.findNavController 也是一样,延迟1毫秒就不报错,不延迟就报错,不知道有正解不?麻烦了 |
给你翻了下代码 val navHostFragment = supportFragmentManager
.findFragmentById(R.id.nav_host_fragment_bankcard) as NavHostFragment
val navController = NavHostFragment.findNavController(navHostFragment)
val bankCardCount = intent?.getIntExtra("bankCardCount",0)
navController.setGraph(
if(bankCardCount == 0) R.navigation.nav_bankcard_add
else R.navigation.nav_bankcard,
// 没有银行卡时,添加银行卡界面直接退出
if(bankCardCount == 0) Bundle().apply { putBoolean("isReturnList",false) }
else null
) <?xml version="1.0" encoding="utf-8"?>
<androidx.fragment.app.FragmentContainerView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/nav_host_fragment_bankcard"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
/> |
在看了这篇文章之后,里面有一个写法,目标是和标题一样,行为应该是切换了
navigation
和startDestination
。结果发生了问题,对大佬的严格深有感悟,受制于自身水平,实在没办法探索。
具体是 FragmentNavigator.java:109
The text was updated successfully, but these errors were encountered: