Skip to content

fun onDestroy() of InstanceKeeper.Instance not called #103

@Petrulak

Description

@Petrulak

Hello, i am playing with your library , its great , but i have run into an issue that the onDestroy() of InstanceKeeper.Instance is not called when i pop a screen.
Here is my code.

// inside of a composable fun
val viewModel = rememberOnRoute(SettingsViewModel::class) { savedState -> SettingsViewModel(savedState) }

class SettingsViewModel(private val context: RouterContext) : InstanceKeeper.Instance {

  init {
    Logger.e("init")
    context.lifecycle.subscribe(object : Lifecycle.Callbacks {
      override fun onCreate() {
        Logger.e("onCreate")
        super.onCreate()
      }

      override fun onDestroy() {
        Logger.e("onDestroy")
       //  this@SettingsViewModel.onDestroy() ->i can call onDestroy directly, but this feels hacky
        super.onDestroy()
      }

      override fun onPause() {
        super.onPause()
      }

      override fun onResume() {
        super.onResume()
      }

      override fun onStart() {
        Logger.e("onStart")
        super.onStart()
      }

      override fun onStop() {
        Logger.e("onStop")
        super.onStop()
      }
    }
    )
  }

  // NOT CALLED WHEN i POP THE SCREEN
  override fun onDestroy() {
    Logger.e("MAIN onDestroy")
    super.onDestroy()
  }

}

Can you maybe guide me on what i have done wrong ?

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions