Skip to content

Instantly share code, notes, and snippets.

@nomanr
Created September 21, 2020 12:45
Show Gist options
  • Save nomanr/c86774f874803498724a5f2a4b2e3d3a to your computer and use it in GitHub Desktop.
Save nomanr/c86774f874803498724a5f2a4b2e3d3a to your computer and use it in GitHub Desktop.
import androidx.hilt.Assisted
import androidx.hilt.lifecycle.ViewModelInject
import androidx.lifecycle.LiveData
import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel
class ExampleViewModel @ViewModelInject constructor(
private val someUseCase: SomeUseCase,
@Assisted private val savedStateHandle: SavedStateHandle
) : ViewModel() {
//Get plain argument
val argumentA: String = savedStateHandle.get<>(KEY_ARGUMENT_A)
// Get argument as LiveData
val argumentA: LiveData<String> = savedStateHandle.getLiveData(KEY_ARGUMENT_A)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment