private val coroutineScope by lazy { CoroutineScope(Dispatcher.IO) }
private val infoSaveModule : DataStoreModule by inject()
coroutineScope.launch {
infoSaveModule.setData(1)
Navigation.findNavController(binding.root).navigate(R.id.action)
}
μ½λ£¨ν΄ μ€μ½ν λ΄μμ Jetpack Navigationμ μ¬μ©νλλ λ€μκ³Ό κ°μ μ€λ₯κ° λ°μνλ€.
λ°±κ·ΈλΌμ΄λ μ€λ λκ° μλ λ©μΈμ€λ λμμ Navigationμ μ¬μ©νκ±°λ, μ½λ£¨ν΄ μ€μ½νμ μ€λ λνμ λ©μΈμ€λ λλ‘ μ§μ ν΄μ£Όλ©΄ ν΄κ²°ν μ μλ€. κ°μμ λͺ©μ μ λ§κ² μ μ νκ² μμ νμ.
1. λ©μΈμ€λ λμμ Navigation μ¬μ©
class MainFragment : Fragment() {
private val coroutineScope by lazy { CoroutineScope(Dispatcher.IO) }
private val infoSaveModule : DataStoreModule by inject()
private fun login(){
...
coroutineScope.launch {
infoSaveModule.setData(1)
}
...
Navigation.findNavController(binding.root).navigate(R.id.action)
}
}
2. μ½λ£¨ν΄ μ€μ½νμ μ€λ λνμ λ©μΈμ€λ λλ‘ λ³κ²½ν΄μ μ¬μ©
class MainFragment : Fragment() {
private val coroutineScope by lazy { CoroutineScope(Dispatcher.Main) }
private val infoSaveModule : DataStoreModule by inject()
...
}