Progress Bar is not dismissed

I don't accomplish to dismiss progress bar in my Android App. I declare an object bar object and get a String calling the doInProgress function and pass to it an object called v1. When the async task finishes his task, why progress bar (wichs appears) is not dismissed as declared in onPostExecute method?

In my activity I call:

ProgressDialog pDialog;
response = new GetString(SecondActivity.this).execute(v1).get();

and this is myAsync Task:

package com.gms;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.impl.client.DefaultHttpClient;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;


public class GetString extends AsyncTask<VariablesTable, Void, String> {

        private Context context;

        public ProgressDialog pDialog;

        public GetString(Context c){
            context = c;
        }           

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            pDialog = new ProgressDialog(context);
            pDialog.setMessage("Loading..");
            pDialog.setIndeterminate(false);
            pDialog.setCancelable(false);
            pDialog.show();
        }


        protected void onPostExecute() {
            // dismiss the dialog once got all details
            if (pDialog.isShowing()){
                pDialog.dismiss();
            }
        }


        @Override
        protected String doInBackground(VariablesTable... obj) {
            // Making HTTP request
            InputStream is = null;

            try {
                    DefaultHttpClient httpClient = new DefaultHttpClient();
                    String paramString = URLEncodedUtils.format(obj[0].cat, "utf-8");
                    obj[0].url += "?" + paramString;
                    HttpGet httpGet = new HttpGet(obj[0].url);

                    HttpResponse httpResponse = httpClient.execute(httpGet);
                    HttpEntity httpEntity = httpResponse.getEntity();
                    is = httpEntity.getContent();          

            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            } catch (ClientProtocolException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }

                BufferedReader reader = null;
                try {
                    reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8);
                } catch (UnsupportedEncodingException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                StringBuilder sb = new StringBuilder();
                String line = null;
                try {
                    while ((line = reader.readLine()) != null) {
                        sb.append(line + "\n");
                    }
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                try {
                    is.close();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                return sb.toString();
        }
    }

Suggestions?? Thanks in advance

Answers


chck post execute, i doubt it works

try changing onPostExecute() to onPostExecute(String resp)


I think the problem is in the way you start your ASyncTask.

response = new GetString(SecondActivity.this).execute(v1).get();

If you are calling that from the UI thread, it will make it block there. Remove the .get() part so the thread can continue running and execute your onPreExecute and onPostExecute function properly.


do a System.out in onPostExecute() method to check whether the control is reaching in this method or not. If onPost gets executed and dialog is not dismissing, then dismiss the dialog in a UI thread --- context.runOnUiThread and if still it doesnt work make the ProgressDialog static(not a solution just a try) and hopefully it will dismiss now.


Need Your Help

How to set memory for the VM in IntelliJ? Do I have to set Tomcat memory options separately?

java tomcat jvm intellij-idea

I'm doing some benchmarking and I want to know how to set memory for both IntelliJ and Tomcat.

Finding out whether a DirectInput device supports XInput (with mingw/gcc)

c++ windows directinput xinput

I'm working on an input system, wrapping DirectInput and XInput. Currently XInput devices are enumerated twice, once as XInput and once as DirectInput (since they support both).

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.