Android tutorials

How to make android studio login page SQL (part 2 )

android studio login page SQL (part 2 ) for beginner in Urdu & Hindi

Android studio login page SQL (part 2 ).

Android studio login page SQL Urdu and Hindi: Welcome to Rise Pakistani Urdu and Hindi tutorial. Today we will continue the second part of android studio login page SQL Urdu and Hindi. You can watch my video tutorial on my website RisePakistani or Youtube channel. If you like my video please like my video. If you have any issue please comment here thank you.

Android studio login page :

Add this code in your class which extends AsyncTask.

    Context context;
// Alert dialog box variable
    AlertDialog alertDialog;

    String s = "";
// create constructor
Class name(Context ctx){
    context= ctx;


Type your class name which extends by Asynctask. Because here we need a constructor which can be declared with the class name. And Context variable hold value which delivered from the main activity.  So we get that value and store in another variable which declared in the top.AlertDialog is used to show value which we will receive from a server.

Background Class:

After making a constructor we will add code in a doBackground class. That will perform an action in the background.

String type, username, password, url_link;
type = voids[0];
username = voids[1];
password = voids[2];
if (type.equals( "Login" )){
    try {
        URL url=new URL( url_link );
        HttpsURLConnection httpsURLConnection = (HttpsURLConnection) url.openConnection();
        httpsURLConnection.setRequestMethod( "POST" );
        httpsURLConnection.setDoInput( true );
        httpsURLConnection.setDoOutput( true );
// out put stream
        OutputStream outputStream=httpsURLConnection.getOutputStream();
// create buffer Writer for writing text to the character output stream
        BufferedWriter bufferedWriter=new BufferedWriter( new OutputStreamWriter( outputStream,"UTF-8" ) );
        String data  = URLEncoder.encode("username", "UTF-8") + "=" +
                URLEncoder.encode(username, "UTF-8");
        data += "&" + URLEncoder.encode("password", "UTF-8") + "=" +
                URLEncoder.encode(password, "UTF-8");
// pass data in bufferwriter
        bufferedWriter.write( data );
// close bufferwriter
// close outputStream
// create input stream
        InputStream inputStream=httpsURLConnection.getInputStream();
// create buffer reader for reading data
        BufferedReader bufferedReader=new BufferedReader( new InputStreamReader( inputStream ) );
// create string variable
        String result="";
        String line ="";
// while loop for storing data in result 
        while ((line = bufferedReader.readLine())!= null){
            result += line;
// when line will get null value while loop will go to end automatically
        return result;
    } catch (MalformedURLException e) {
    } catch (IOException e) {


The doBackground class will receive an array of the parameter,  zero indexes contain a first value which type ( Login) the second value will receive on the first index which is a username and third value will receive on the second index which is password. After that, we will use URL which is built in the android studio. After that, we will use HttpsURLConnection which used to make a connection between app and server. We will set type method (get or post) for the purpose of sending data from mobile to server.

Why do we use BufferedWriter in Java?

BufferedWriter is a subclass of class. BufferedWriter writes text to the character output stream, buffering characters so as to provide for the efficient writing of single characters, arrays, and strings. The buffer size may be specified, or the default size may be used.


Click here if you want to watch first tutorial Android studio SQl log in page.


Related Articles

Adblock Detected

Please consider supporting us by disabling your ad blocker