Home > Mobile >  how to save the reached level in a quiz app
how to save the reached level in a quiz app

Time:09-10

I'm new to kotlin and android app developpement in general and I want to make a Quiz app with jetpack compose not XML, and this app has multiple levels and when the user starts the quiz if he decides to stop playing in a certain level and quit the app i want to save that level so next time when he come back to play he's gonna start from the same level he stopped. I've tried to use preference datastore but it doesn't seem to work. this is my Datastore class:

The OP's screenshot showing an unused function

You'll have to call saveScreen() or saveScreen.invoke() somewhere. Why not just make it a normal function though?

// call this when you want to save the screen
private fun saveScreen() {
    // scope.launch { datastore.Save etc }
}

Unless doing things this way is a Compose thing (I've never used it). Either way, that function you're defining isn't called anywhere, so your screen isn't being stored!

  • Related