Let’s Build a Login System in Android
We are going to build an android application that authenticates its users through a RESTful service using Java and Retrofit tool.

User Authentication
Whenever we plan to build a virtual platform for our users, the basic requirement is to maintain the data of the users and ensuring them a secure place to provide their data for us to process. The same corresponds to an android application too.
This article was originally published at Simplecoding.dev
In this tutorial, we are going to build an android application that authenticates its users through a RESTful service using Java and Retrofit tool. The RESTful service accessed here is built using Spring boot and its tutorial can be found here.
And also, we need to host our Spring Backend to the cloud, to access that as a RESTful service. The tutorial for the same can be found here.
The bitbucket repositories for this tutorial can be found below in the resources section.
Requirements
- Android Studio
- Android Virtual Device (AVD)
- Android SDK Tools
- Cloud hosted Spring Backend
- Retrofit
Steps to setup your work environment in Android Studio can be found here.
Project Creation
After completing the IDE setup, open Android Studio -> Click on New Project -> Select empty activity -> Select Java for Language -> Select android SDK such that our app runs on all devices -> Click on finish -> Wait until all the gradle scripts get downloaded. We can start working on our project at once the build is successful.


Creating Activities
Activities are the basic blocks to build an android application. Go to java main package where you can find the Main Activity, which is the entry point for our application. We need three more activities for our application. We can create an empty activity by following the given steps: Right click on the package -> New -> Activity -> Empty Activity. By following these steps, make the following activities -
- Register Activity
- Login Activity
- Dashboard Activity
Each activity will be individually having a layout file in xml which is used to create the User Interface for our application. The layouts can be found in the main > res > layout folder.
Dependencies
We need only two additional dependencies to make this application. One is the Retrofit dependency and the other is the Gson converter dependency.
implementation ‘com.squareup.retrofit2:retrofit:2.4.0’implementation ‘com.squareup.retrofit2:converter-gson:2.4.0’Copy paste the above two lines to the dependencies section of app level gradle file and sync the project to get the dependencies.
Retrofit is the REST API client that can send requests and receive response from our RESTful service. Gson converter is used to send and receive data as JSON (JavaScript Object Notation)
Permissions
As our application is simply aimed at communicating with the REST API, which is hosted on the Internet, we need Internet permissions only.
<uses-permission android:name="android.permission.INTERNET" />The above line should be inserted as a tag in the app/src/main/AndroidManifest.xml. The complete file is as below -












