title: how to direct login activity to different user profile
body: <p>I'm doing an android application and after login in i have two different types of users profiles in my case a simple client and and a pharmacist with advanced configurations ,I have been looking in the internet about how to direct my login activity according to the user account registered in my database but it didn't help, i'm using android studio. this is my loginactivity.java </p>
  
  <pre><code>package com.example.yh.log;
  
  import android.app.Activity;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.app.Dialog;
  import android.app.ProgressDialog;
  import android.content.Intent;
  import android.os.AsyncTask;
  import android.support.v7.app.ActionBarActivity;
  import android.os.Bundle;
  import android.util.Log;
  import android.view.Menu;
  import android.view.MenuItem;
  import android.view.View;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.TextView;
  import android.widget.Toast;
  
  import java.io.BufferedReader;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.InputStreamReader;
  import java.io.PrintWriter;
  import java.io.UnsupportedEncodingException;
  import java.net.HttpURLConnection;
  import java.net.URL;
  import java.util.ArrayList;
  import java.util.List;
  import java.util.logging.Level;
  import java.util.logging.Logger;
  
  public class MainActivity extends Activity {
      private EditText TextUserName;
      private EditText TextPassword;
      public static final String USER_NAME = "USERNAME";
      String username;
      String password;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
  
  
  }
  public void onLoginClick(View view){
  TextUserName = (EditText) findViewById(R.id.editusername);
  TextPassword = (EditText) findViewById(R.id.editpassword);
  
  username=TextUserName.getText().toString();
  password=TextPassword.getText().toString();
  if(username.isEmpty())
      Toast.makeText(getBaseContext(),"Entrez votre username",Toast.LENGTH_SHORT).show();
  else if(password.isEmpty())
      Toast.makeText(getBaseContext(),"Entrez votre mot de passe",Toast.LENGTH_SHORT).show();
  else {
      String urlString = "http://192.168.173.1/Search/login.php";
      LoginTask loginTask = new LoginTask();
      loginTask.execute(urlString);
  }
  }
  private class LoginTask extends AsyncTask&lt;String,Void,String&gt;
  {
      private Dialog loadingDialog;
    @Override
    protected void onPreExecute() {
    super.onPreExecute();
   loadingDialog = ProgressDialog.show(MainActivity.this, "Please wait", "Loading...");
  }
      @Override
      protected String doInBackground(String... params) {
          HttpURLConnection c=null;
          try {
              String urlString=params[0];
              URL url=new URL(urlString);
              c=(HttpURLConnection)url.openConnection();
              c.setRequestMethod("POST");
              c.setConnectTimeout(15000 /* milliseconds */);
              c.setDoInput(true);
              c.setDoOutput(true);
              c.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
              String s = "username="+username+"&amp;password=" + password;
          c.setFixedLengthStreamingMode(s.getBytes().length);
          PrintWriter out = new PrintWriter(c.getOutputStream());
          out.print(s);
          out.close();
  
          c.connect();
          int mStatusCode = c.getResponseCode();
          String result="";
          switch (mStatusCode) {
              case 200:
                  BufferedReader br = new BufferedReader(new InputStreamReader(c.getInputStream()));
                  StringBuilder sb = new StringBuilder();
                  String line;
                  while ((line = br.readLine()) != null) {
                      sb.append(line).append("\n");
                  }
                  br.close();
                  result =  sb.toString();
  
          }
          return result;
      } catch (Exception ex) {
          Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
          return "Error connecting to server";
      } finally {
          if (c != null) {
              try {
                  c.disconnect();
              } catch (Exception ex) {
                 Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
                  }
              }
          }
      }
  @Override
  protected void onPostExecute(String s) {
          //super.onPostExecute(s);
          String ss = s;
          loadingDialog.dismiss();
          if(ss.equals("successclient\n")) {
              Intent intent = new Intent(MainActivity.this, UserProfile.class);
          }else {
              if (ss.equals("successpharmacien\n")) {
                  Intent intent = new Intent(MainActivity.this, PharmacienProfile.class);
  
              intent.putExtra(USER_NAME, username);
              finish();
              startActivity(intent);
          }else{
                 Toast.makeText(getApplicationContext(), ss, Toast.LENGTH_LONG).show();
  
      }}
  }
  }
  </code></pre>
  
  <p>this is the php code</p>
  
  <pre><code>&lt;?php
  
  
   try
  {
      // connecting to MySQL
      $bdd = new PDO('mysql:host=localhost;dbname=application;charset=utf8', 'root', '');
  
  }
  catch(Exception $e)
  {
  
  // In case of an error, we display a message and stop everything
      die('Erreur : '.$e-&gt;getMessage());
  
  }
      //Getting values 
      $username = $_POST['username'];
      $password = $_POST['password'];
  
  
  
  //contact surgat
  // display every input one after another
  
  $listephar = $bdd-&gt;query("SELECT * FROM phamacien  WHERE emailpharmacien='$username' AND motpasspharmacien='$password'");
  
  $listeclient = $bdd-&gt;query("SELECT * FROM client  WHERE emailclient='$username' AND motpass='$password'");
  
  while ($pharmacien = $listephar-&gt;fetch())
  {
  
      //if we got some result 
      if(isset($pharmacien)){
          //displaying success 
          echo "successpharmacien";
          }else{
          //displaying failure
  
  
  while ($client = $listeclient-&gt;fetch())
  {
      if (isset($client)){
              echo "successclient";
          }else{
          //displaying failure
          echo "failure";
  
  
  }
  }}}
  $listephar-&gt;closeCursor();      
  $listeclient-&gt;closeCursor(); 
  ?&gt;
  </code></pre>