https://kotlinlang.org logo
#compose
Title
# compose
d

Deepak Gahlot

01/11/2022, 7:35 AM
Hello All,
🧵 1
🙂 1
Copy code
java.lang.IllegalArgumentException: SavedStateProvider with the given key is already registered
        at androidx.savedstate.SavedStateRegistry.registerSavedStateProvider(SavedStateRegistry.java:111)
        at androidx.lifecycle.SavedStateHandleController.attachToLifecycle(SavedStateHandleController.java:50)
        at androidx.lifecycle.SavedStateHandleController.create(SavedStateHandleController.java:70)
        at androidx.lifecycle.SavedStateViewModelFactory.create(SavedStateViewModelFactory.java:115)
        at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.kt:169)
        at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.kt:139)
        at androidx.lifecycle.viewmodel.compose.ViewModelKt.get(ViewModel.kt:87)
        at androidx.lifecycle.viewmodel.compose.ViewModelKt.viewModel(ViewModel.kt:72)
        at androidx.navigation.compose.NavBackStackEntryProviderKt.SaveableStateProvider(NavBackStackEntryProvider.kt:86)
        at androidx.navigation.compose.NavBackStackEntryProviderKt.access$SaveableStateProvider(NavBackStackEntryProvider.kt:1)
        at androidx.navigation.compose.NavBackStackEntryProviderKt$LocalOwnersProvider$1.invoke(NavBackStackEntryProvider.kt:51)
        at androidx.navigation.compose.NavBackStackEntryProviderKt$LocalOwnersProvider$1.invoke(NavBackStackEntryProvider.kt:50)
I'm getting this exception when i launch an
Copy code
rememberLauncherForActivityResult(
    ActivityResultContracts.OpenDocument()
Attach a file and click on one of the button which triggers an action to go to a previous screen in the navigation graph using the Navigate.up() function. Any thoughts on what could be causing this. If any more info is indeed please let me know.
@Colton Idle any thoughts ? I tried cleaning the ViewModel store from the owner when the onPause()/onStop() is being called, but that does not help.
c

Colton Idle

01/11/2022, 3:41 PM
You're doing activity <> activity result stuff it seems? I have not yet had to tackle any problems with additional activities or activity results. sorry. I could have sworn one of the compose templates did?
I think jetsurvey has a camera intent which would mean it passes data back via a result. maybe you can take a peak at the code here? https://github.com/android/compose-samples/tree/main/Jetsurvey
d

Deepak Gahlot

01/11/2022, 3:47 PM
Sure thanks, i will check this first.
I updated the Navigation-compose library to 2.4.0-rc01 and now i'm getting a different error
Copy code
java.lang.IllegalStateException: ViewModelStore should be set before setGraph call
This Exception is coming as soon i return to the app after selecting the document
c

Colton Idle

01/12/2022, 6:22 PM
Yeah, id file a bug my friend. cheers
3 Views