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();
            }
      }

5 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. Very informative ..i suggest this blog to my friends..Thank you for sharing
    Best Android Training in Velachery | android development course fees in chennai

    ReplyDelete