In this tutorial, you will learn the following.
- How to add retrofit dependency in android .
- How to log retrofit request body and response body.
- How authenticate user from backend.
- How to redirect user to a new activity when user login is success.
Steps of authenticating user from database using retrofit.
- Adding the following dependencies.
- Retrofit: type-safe HTTP client for Android and Java.
- Gson: Convertor Library
- OkHttp interceptor: Logs HTTP request and response data.
- Create UserService were all the calls will be performed.
- Create ApiClient Class which will serve as a retrofit instance.
- Design a login screen with two edit text (username, password ) and a login button.
- Listen when the login button is clicked, check if the user has keyed in username and password if yes perform login else toast an error message.
- Create a new activity where the user will be redirected on successful login when login response is successful, Redirect user, and pass the username to other activity.
Check out the source code from my github account.