AsyncTask.execute() doesn't wait for doInBackground to complete
<p>I know this is a duplicate question but please hold on. I have read some similar questions and answer but none of them seems working for me.</p>

<p>What to do:
I have to do a search which will send a request to a web service and receive a response.
As i can't consume network on UI thread, I used <code>AsyncTask</code>. </p>

<p>What i tried:
I tried using <code>task.execute()</code> this returns immediately without even showing  progressdialog box and i receive response as null (set in <code>onPostExecute</code>)</p>

<p>if i use <code>task.execute.get()</code> then it freezes screen and again no dialog box shows up (but i receive response correctly).</p>

<p>Below is my code with task.execute. Kindly correct me.</p>

<pre><code>public class LookIn extends AppCompatActivity implements View.OnClickListener{
private Button btn=null;
private TextView txtPinCode=null;
private Service service=null;
private final static  int timeout=20;
private String jsonResponse;
//private ProgressBar helperSearchProgressBar;
private String pincode="";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_look_in);
    btn=(Button)findViewById(R.id.button);
    btn.setOnClickListener(this);
    txtPinCode=(TextView) findViewById(R.id.txtPinCode);
    this.service=(Service) ParamFactory.getParam(ConstantLabels.SELECTED_SERVICE_ID);
   // this.helperSearchProgressBar=(ProgressBar)findViewById(R.id.helperSearchProgressBar);
}


@Override
public void onClick(View v) {

    String pincode= txtPinCode.getText().toString();
    if(pincode==null || pincode.isEmpty() || pincode.length()!=6)
    {
        this.txtPinCode.setError("Please enter a 6 degit pin code from 700000 to 700200");

        return;
    }

    ParamFactory.setParam(ConstantLabels.PINCODE_ID,pincode);
    this.pincode=pincode;
    loadHelper();

    Intent intent= new Intent(LookIn.this,SearchResult.class);
    startActivity(intent);
}


public void setJsonResponse(String jsonResponse)
{
    this.jsonResponse=jsonResponse;
}
private void loadHelper()
{

    Log.v("Callme", "Running thread:" + Thread.currentThread().getId());
    ArrayAdapter&lt;User&gt; adapter=null;
    String params=this.pincode+","+this.service.getId();
    List&lt;User&gt; result=null;
    try {
        new CallmeGetHelperAsyncTask().execute(params); //my task.execute()
        result= RestUtil.getUserList(jsonResponse);
        adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, result);
        ParamFactory.setParam("getHelperForService", adapter);
    }
    catch(JSONException x)
    {
        Log.e("Callme", Log.getStackTraceString(x));
    }

}
class CallmeGetHelperAsyncTask extends AsyncTask&lt;String,Void,String &gt; {
   // private Context context=null;
    private ProgressDialog dialog=null;
    private String jsonResponse;
    private LookIn activity;
    public CallmeGetHelperAsyncTask(){}
    public CallmeGetHelperAsyncTask(LookIn activity)
    {
        this.activity=activity;
    }
    @Override
    protected void onPreExecute() {
       this.dialog= new ProgressDialog(LookIn.this);
        this.dialog.setMessage("Loading...");
        this.dialog.show();
        Log.v("Callme","Dialog Shown");
    }

    @Override
    protected void onPostExecute(String s) {
        if(s!=null)
        {
            this.activity.setJsonResponse(s);
        }
        else
        {
            Log.v("Callme","kill me");
        }
        if(this.dialog.isShowing())
        {
            Log.v("Callme","Closing Dialog");
            this.dialog.dismiss();
        }

    }

    @Override
    protected String doInBackground(String... params) {
        Log.v("Callme","From Background:"+Thread.currentThread().getId());
        String pincode=params.clone()[0].split(",")[0];
        String serviceId=params.clone()[0].split(",")[1];
        String url=String.format(URL.GET_HELPER,serviceId,pincode);
        jsonResponse= null;
        try {
            jsonResponse = RestUtil.makeRestRequest(url);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return jsonResponse;
    }
}

}
</code></pre>

<p>Note: I haven't tried using while loop to waiting for the asynctask, because i think that will also end up freezing my screen. Please correct me if i am wrong</p>