To many arguments when using android navigation safeArgs

1.3k Views Asked by At

i am creating navigation graph in android, and i give args for the destination, but when I called the function, it was saying too many arguments.

  • already setup on build.gradle (app) apply plugin: 'androidx.navigation.safeargs'

  • already setup on build.gradle (.) dependecies { classpath "android.arch.navigation:navigation-safe-args-gradle-plugin:1.0.0-alpha05" }

  • this is my source of my navigation

<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>
  • this is my destination of my navigation
<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>
  • this is my kotlin code for source of my navigation
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)
    }
}

When I called it inside of unused gameFinished function, GameFragmentDirections.actionGameFragmentDestinationToScoreFragment(score) it was saying to many arguments, any idea how to solve?

0

There are 0 best solutions below