ViewModel — — A Simple Login using viewmodel Android in Kotlin

In this tutorial, we are going to see how to use viewmodel for login in your Android application.

ViewModel: It is a bridge between the View and Model(business logic). It does not have any clue which View has to use it as it does not have a direct reference to the View. So basically, the ViewModel should not be aware of the view who is interacting with. It interacts with the Model and exposes the observable that can be observed by the View.

  1. Go to File ⇒ New Project. .select Empty Activity and proceed.
  2. Add dependencies : — -

3.activity_main: — — -

4.LoginActivity: — -

5.UserViewModel: — —

6: finally HomeActivity


8.Manifest: — -

9:output/Screenshots: — -

1.login screen
2.home screen



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store