Below is a simple android application for login. It accepts user name and password from the user and sends to remote server application for validation/authentication. Finally displays the result to the user.
Step 1: Create the layout for the application.FirstApp/res/layout/activity_main.xml
Step 2: Create a java class to create UI threads.com.example.firstapp.clientside.LoginLayout.java
Note: Please use your IP address in below statement;
response = SimpleHttpClient.executeHttpPost("http://192.168.1.3:8084/LoginServer/login.do", postParameters);
http://192.168.1.3:8084/LoginServer/login.do is the url of my server application's servlet.
Step 3: Create a java class to post the username and password to a remote server.
Normally the database and other resources like servlets will reside in separate computer and the Android application will communicate with that computer to authenticate the user. Thats why we are creating this java class.
Step 4: Add permissions to access internetTo be able to access the internet from the application (To send the user name and the password to the remote machine) we need to add permissions using following line to the AndroidManifest.xml file
So your final AndroidManifest.xml file will look like;
Step 5: Create the login server applicationWe are done at the android application side. Now we need the server application to check the user name and the password. Here I have used a simple web application with a servlet. This application runs in a Tomcat server. You can have your own logic to validate the username and the password in the servlet. You can do database operations etc. But here I am just doing static validation of the username and password.
Step 6: We are done and ready to run the application.
Note that this application is just to demonstrate how to make a communication with a remote application. It is always recommended to consider using AsyncTask while making network calls.
This example has been upgraded with SSL support and AsynTaskSupport here. Have a look..
Source code of the android app: LoginApp.zip
Please dont forget to share your views !!
Source code of the server app: LoginServer.zip