Skip to content

lotosbin/ScopeViewModel

Repository files navigation

ScopeViewModel

share viewModel between activities with same key

Usage

class MainApplication : Application() {
    override fun onCreate() {
        super.onCreate()
        ScopeViewModel.init(this)
    }
}

class Test1Activity : AppCompatActivity() {
    private val viewModel by lazy {
        getViewModel<TestViewModel>(intent.getStringExtra("name") ?: "")
    }
    //...
}
class Test2Activity : AppCompatActivity() {
    private val viewModel by lazy {
        getViewModel<TestViewModel>(intent.getStringExtra("name") ?: "")
    }
    //...
}

Test1Activity & Test2Activity instance's share same viewmodel when there intent has same "name" extra value

About

share viewModel between activities with same key

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages