Hello, I've a difficult question. I get  this erro...
# android
h
Hello, I've a difficult question. I get  this error   'java.lang.IllegalArgumentException: SavedStateProvider with the given key is already registered'. What is the reason?
Copy code
Fragment
private var instance: LoginFragment? = null
 private val viewModel by viewModels<AuthViewModel>()
 override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        binding = FragmentLoginBinding.bind(view)
        instance =this
}

fun login(): String {
    viewModel.login(clientId, partner.toString(), password)
    val clientId = binding.editTextTextEmailAddress.text.toString().trim()

    val encrypted = encrypt(clientId, publicKey)
  
    return encrypted
}
RemoteDataSource
Copy code
private fun getRetrofitClient(): OkHttpClient {

    val str= LoginFragment().getInstance()?.login()
....
😶 2
android dance 1
c
1. your question is not Kotlin related, please read the channel description before posting questions. 2. Why is your data source creating the fragment? That’s not how fragments in Android work.
Your whole architecture is off. The data source should be part of the view model and then send the result back to the fragment via the view model through i.e. live data that the fragment observes.
c
@Hovhannes this channel is for kotlin specific questions related to android, so people will likely keep marking your questions as 😶 . You'll have better luck trying other communities like the /r/androiddev subreddit/discord, or stackoverflow.