onPostExecute getting null Json
<p>I want to pass data from <code>RegisterActivity</code> to <code>mySqlDatabase</code>, using a new class called <code>BackgroundTask</code> (which extends AsyncTask). After <code>onPreExecute()</code>, <code>doInBackground()</code> and <code>onPostExecute()</code> are called, <code>onPostExecute</code> is getting a <code>null</code> value to my attribute JSON.</p>

<p><strong>BackGroundTask</strong></p>

<pre><code>public class BackgroundTask extends AsyncTask&lt;String,Void,String&gt; {
String registerUrl = "http://127.0.0.1/gestion/register.php";
Context ctx ;
Activity activity ;
ProgressDialog progressDialog ;
AlertDialog.Builder builder ;
public BackgroundTask(Context ctx) {
    this.ctx = ctx;
    activity = (Activity)ctx;
}

@Override
protected void onPreExecute() {
    builder =  new AlertDialog.Builder(activity);
    progressDialog =  new ProgressDialog(ctx);
    progressDialog.setTitle("Please Wait ");
    progressDialog.setMessage("Connecting Server ... ");
    progressDialog.setIndeterminate(true);
    progressDialog.setCancelable(false);
    progressDialog.show();

}

@Override
protected String doInBackground(String... params) {
    String method = params[0];
    if (method.equals("register")){
        try {
            URL url = new URL(registerUrl);
            HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
            httpURLConnection.setRequestMethod("POST");
            httpURLConnection.setDoOutput(true);
            httpURLConnection.setDoInput(true);
            OutputStream outputStream = httpURLConnection.getOutputStream();
            BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream,"UTF-8"));
            String name = params[1];
            String email = params[2];
            String password = params[3];
            String data = URLEncoder.encode("name","UTF-8")+"="+URLEncoder.encode(name,"UTF-8")+"&amp;"+
                          URLEncoder.encode("email","UTF-8")+"="+URLEncoder.encode(email,"UTF-8")+"&amp;"+
                          URLEncoder.encode("password","UTF-8")+"="+URLEncoder.encode(password,"UTF-8");
            bufferedWriter.write(data);
            bufferedWriter.flush();
            bufferedWriter.close();
            outputStream.close();
            InputStream inputStream = httpURLConnection.getInputStream();
            BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(inputStream));
            StringBuilder stringBuilder =  new StringBuilder();
            String line  =  "" ;
            while ((line=bufferedReader.readLine())!=null){
                stringBuilder.append(line+"\n");
            }
            httpURLConnection.disconnect();
            Thread.sleep(5000);
            return stringBuilder.toString();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    return null;
}

@Override
protected void onProgressUpdate(Void... values) {
    super.onProgressUpdate(values);
}

@Override
protected void onPostExecute(String json) {
  if(json == null){
      try {
          progressDialog.dismiss();
          showDialog("Registration Failed ", "Json Null" , "reg_false" );
          JSONObject jsonObject = new JSONObject(json);
          JSONArray jsonArray =jsonObject.getJSONArray("server_response");
          JSONObject jo = jsonArray.getJSONObject(0);
          String code = jo.getString("code");
          String message = jo.getString("message");
          if(code.equals("reg_true")){
              showDialog("Registration sucess ", message , code );
          }else if(code.equals("reg_false")){
              showDialog("Registration Failed ",message,code);
          }
      } catch (Exception e) {
          e.printStackTrace();
      }
  }else{
      showDialog("Registration Failed ", "Json not  Null" , "reg_false" );
  }
}

public void showDialog(String title ,  String message, String code ){
    builder.setTitle(title);
    if(code.equals("reg_true")|| code.equals("reg_false")){
        builder.setMessage(message);
        builder.setPositiveButton("OK", new DialogInterface.OnClickListener(){

            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                activity.finish();
            }
        });
        AlertDialog alertDialog = builder.create();
        alertDialog.show();

    }
}
</code></pre>

<p><strong>RegisterActivity</strong></p>

<pre><code> public void initGUI(){
    name = (EditText) findViewById(R.id.reg_name);
    email = (EditText) findViewById(R.id.reg_email);
    password = (EditText) findViewById(R.id.reg_password);
    conPassword = (EditText) findViewById(R.id.reg_con_password);
    register =(Button)findViewById(R.id.btn_reg);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_register);
    initGUI();

    register.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (name.getText().toString().equals("") || email.getText().toString().equals("")  || password.getText().toString().equals("")|| conPassword.getText().toString().equals("")){
                builder = new AlertDialog.Builder(RegisterActivity.this);
                builder.setTitle("Mooooochkila 1 ");
                builder.setMessage(" walm3alam 3amar kolchi ola may3bak hal");
                builder.setPositiveButton("Wakha", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.dismiss();
                            }
                        }

                );
                AlertDialog alertDialog = builder.create();
                alertDialog.show();

            }
            else if (!(password.getText().toString().equals(conPassword.getText().toString()))){
                builder = new AlertDialog.Builder(RegisterActivity.this);
                builder.setTitle("Mooooochkila 2 ");
                builder.setMessage("3awati lpassword Ghalet 3awd 4awdo");
                builder.setPositiveButton("Wakha", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.dismiss();
                                password.setText("");
                                conPassword.setText("");
                            }
                        }

                );
                AlertDialog alertDialog = builder.create();
                alertDialog.show();
            }
            else{
                BackgroundTask backgroundTask = new BackgroundTask(RegisterActivity.this);
                backgroundTask.execute("register", name.getText().toString(), email.getText().toString(),password.getText().toString());
            }
        }
    });
}
</code></pre>