8.5 C
New York
Tuesday, May 26, 2020
No menu items!
Home Android tutorials How to make android studio login page SQL (part 2 )

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

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 java.io.Writer 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.


- Advertisment -

Most Popular

What is Happening? Now King of Romance Rishi is with Irfan

King of Romance Rishi Kapoor is now With Irfan Khan It is really something unreal happening now Yesterday you hear about Irfan. The demise of...

Irfan Khan The Brand in Khan’s Bollywood is No more now

Irfan Khan The Brand in Khan's Bollywood It is heartbreaking to know that the person who changed the dynamics of Cinema is no more now....

Umar Akmal banned for three years Shocking decission| Spot Fixing

Umar Akmal Banned for three years This is really big news in the current context the big fish of Pakistan cricket Umar Akmal is now...

Pakistan Corona and Imran Khan, Will Pakistan Knock It out?

Pakistan, Corona, and Imran Khan Prime Minister Khan is the frontman to deal with the current scenes. Pakistan can not afford more corona stuff. The...