Q:

UI delayed showing with asynctask

I defined an AsyncTask in a button's onclicklistener, and once user clicks the button, ideally progress dialog shows while asynctask downloading. 
However, progress dialog just flashes in and disappears before the results returned, and the button gets focused while the asynctask works in the background. 
Can someone help me figure out what I did wrong here? Code snippet:
    final ProgressDialog progressDialog = new ProgressDialog(context);
    progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);

    ((Button)findViewById(R.id.buttonLoginActivity)).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            AsyncTask<Void, Void, Void> downloadTask= new AsyncTask<Void, Void, Void>(){
                @Override
                protected Void doInBackground(Void... params) {
                    String data = Service.getSomeData();
                            context.getContentResolver.notifyChange("content://some_url");
                        return null;
                }

                @Override
                protected void onPostExecute(Void result) {
                    super.onPostExecute(result);
                    if(progressDialog== null) return;
                    if(progressDialog!=null) {
                        progressDialog.dismiss();
                        progressDialog = null;
                    }
                }
            };

            progressDialog.show();

            downloadTask.execute();
            try{
                downloadTask.get();
            }catch(Exception e){
                e.printStackTrace();
                return;
            }
        }
    });

A:

Don't use get()
downloadTask.get();

this is a blocking call. From the Docs

Waits if necessary for the computation to complete, and then retrieves its result.

Just use execute() as you are then do what you need with the results in onPostExecute()

