Why is my "email" in the bundle and the arguments is unresolved reference?

Viewed 33

private lateinit var appBarConfiguration: AppBarConfiguration private lateinit var binding: ActivityMainBinding private lateinit var db: FirebaseFirestore

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)

    binding = ActivityMainBinding.inflate(layoutInflater)
    setContentView(binding.root)

    db = FirebaseFirestore.getInstance()

    setSupportActionBar(binding.appBarMain.toolbar)

    /*binding.appBarMain.fab.setOnClickListener { view ->
        Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
            .setAction("Action", null).show()
    }*/
    val drawerLayout: DrawerLayout = binding.drawerLayout
    val navView: NavigationView = binding.navView
    val navController = findNavController(R.id.nav_host_fragment_content_main)

    val bundle = Bundle()
    bundle.putString("email", email)
    HomeFragment.arguments = bundle
    // Passing each menu ID as a set of Ids because each
    // menu should be considered as top level destinations.
    appBarConfiguration = AppBarConfiguration(
        setOf(
            R.id.nav_home, R.id.nav_daily_meal, R.id.nav_favourite, R.id.nav_my_cart
        ), drawerLayout
    )
    setupActionBarWithNavController(navController, appBarConfiguration)
    navView.setupWithNavController(navController)
}
1 Answers

First from where your are passing data pass bundle like this

val bundle = bundleOf("email" to 'test@gmail.com')
view.findNavController().navigate(R.id.newScreen, bundle)

then data from bundle like this

val email = arguments?.getString("email")
Related