I’ve been trying to release this tutorial quite a while. At last after a long hard effort. Since HttpClient is not supported any more in Android SDK 23, I have to resort to org.json.JSONObject and java.net.HttpURLConnection library to do online database with JSON.
The objective of this tutorial is to log-in from a mobile client with the username and password stored in an online database facility.
STEP 1: Create a new Android project, this time choose the LoginActivity .
As the interface is provided by the ListActivity template, I will not elaborate.
STEP 2. Add the HttpHandler helper class.
This helper class is to check several errors of HTTP data format. It is also to convert HTTP stream into STRING.
Add JAVA the file to the main package.
STEP 3: The main java file to handle button LOGIN click and connection to the online server.
The code is too long, I just highlight several important functions.
The UserLoginTask class that implemented in AsyncTask (multi-threading).
The loginVerification function to display dialog box to the login status.
STEP 4: The middleware in the online server
DOWNLOAD THE COMPLETE SOURCE CODE here…https://drive.google.com/file/d/0B5_Hw_xzXWcXbm8xTHZtLVI3bTg/view?usp=sharing
Need face-to-face lesson?, we also provide Android Studio training, 0129034614
Disclaimer: Intermediate level. This tutorial works on Android Studio 2.2. Should you have any difficulties, leave your comment in the comment section.
SHARE to your friends...