Pages

Tuesday, 27 March 2012

Show Progress Dialog inside AsyncTask in Android

private class performBackgroundTask extends AsyncTask < Void, Void, Void > 
     {
        private ProgressDialog pdia;

        @Override
        protected void onPreExecute(){
           super.onPreExecute();
                pdia = new ProgressDialog(FriendList.this);
                pdia.setMessage("Loading...");
                pdia.show();   
        }

        @Override
        protected Void doInBackground(Void... params) {
            // TODO Auto-generated method stub
            asybcTastRun = new AsyncFacebookRunner(LoginActivity.facebook);
            asybcTastRun.request("me/friends", new FriendCallback());
            return null;
        }

         protected void onPostExecute(String result){
              // super.onPostExecute(result);
                    pdia.dismiss();
            }
      }

6 comments:

  1. Very useful example.Thanks
    here is another useful example that lets you use ProgressDialog using threads and handlers also . http://blog.creatiosoft.com/?p=1316

    ReplyDelete
  2. Simple but effective example, But in this way, the progress dialog spinner is not animating. why?

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. This information is impressive; I am inspired with your post writing style & how continuously you describe this topic. After reading your post, thanks for taking the time to discuss this, I feel happy about it and I love learning more about this topic.Android Training institute in chennai with placement | Best Android Training in velachery

    ReplyDelete