Created
May 1, 2021 12:35
-
-
Save manuelvicnt/cde90b59eaa59bfb8382740fe7b313f9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@HiltAndroidApp // Setup Hilt in your app | |
class MyApplication : Application() { ... } | |
// Make Hilt aware of this ViewModel | |
@HiltViewModel | |
class LoginViewModel @Inject constructor( | |
private val savedStateHandle: SavedStateHandle, | |
/* ... Other dependencies Hilt takes care of ... */ | |
) : ViewModel() { ... } | |
// Make the activity use the right ViewModel factory and | |
// inject other dependencies | |
@AndroidEntryPoint | |
class LoginActivity : AppCompatActivity() { | |
private val loginViewModel: LoginViewModel by viewModels() | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
// loginViewModel is ready to be used | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment