使用Android导航safeArgs

问题描述

我正在android中创建导航图,并为目的地指定了args,但是当我调用该函数时,它说了太多参数。

  • 已在build.gradle(应用程序)apply plugin: 'androidx.navigation.safeargs'

    上进行设置
  • 已在build.gradle(。) dependecies { classpath "android.arch.navigation:navigation-safe-args-gradle-plugin:1.0.0-alpha05" }

    上进行设置
  • 这是我导航的来源

<fragment
        android:id="@+id/game_fragment_destination"
        android:name="com.example.apparchitectureuilayer.screen.game.GameFragment"
        android:label="GameFragment"
        tools:layout="@layout/fragment_game">
        <action
            android:id="@+id/action_game_fragment_destination_to_scoreFragment"
            app:destination="@id/score_fragment"
            app:launchSingleTop="true"
            app:popUpTo="@+id/title_destination" />
    </fragment>
  • 这是我导航的目的地
<fragment
        android:id="@+id/score_fragment"
        android:name="com.example.apparchitectureuilayer.screen.score.ScoreFragment"
        android:label="ScoreFragment"
        tools:layout="@layout/fragment_score">
        <action
            android:id="@+id/action_score_fragment_to_game_fragment_destination"
            app:destination="@id/game_fragment_destination" />
        <argument
            android:name="score"
            android:defaultValue="0"
            app:argType="integer" />
    </fragment>
  • 这是我的导航来源的kotlin代码
class GameFragment : Fragment() {

    private var word = ""
    private var score = 0
    private lateinit var wordList: MutableList<String>

    private lateinit var binding: FragmentGameBinding
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
    }

    override fun onCreateView(
        inflater: LayoutInflater,container: ViewGroup?,savedInstanceState: Bundle?
    ): View? {
        return inflater.inflate(R.layout.fragment_game,container,false)
    }

    private fun gameFinished() {
        val action = GameFragmentDirections.actionGameFragmentDestinationToScoreFragment(score)
        NavHostFragment.findNavController(this).navigate(action)
    }
}

当我在未使用的gameFinished函数中调用它时,GameFragmentDirections.actionGameFragmentDestinationToScoreFragment(score) 有人在说很多论点,知道如何解决吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...