Answers for "viewmodelprovider deprecated"

2

viewmodelproviders deprecated

JAVA
replace :
customViewModel    = ViewModelProviders.of(this).get(CustomViewModel.class);

with:
customViewModel    = new ViewModelProvider(this).get(CustomViewModel.class);


KOTLIN
replace:
customViewModel    = ViewModelProviders.of(this).get(CustomViewModel::class.java)

with:
customViewModel    = ViewModelProvider(this).get(CustomViewModel::class.java)
Posted by: Guest on May-07-2020
2

viewmodelproviders deprecated

// With ViewModelFactory   
val viewModel = ViewModelProvider(this, YourViewModelFactory).get(YourViewModel::class.java)


//Without ViewModelFactory
val viewModel = ViewModelProvider(this).get(YourViewModel::class.java)
Posted by: Guest on May-01-2020
1

viewmodelinject deprecated

@HiltViewModel
class MyViewModel @Inject constructor(
    private val repository: Repository,
    private val savedStateHandle: SavedStateHandle
) : ViewModel(), LifecycleObserver {

    // Some code
}
Posted by: Guest on February-17-2021

Code answers related to "viewmodelprovider deprecated"

Browse Popular Code Answers by Language