Wednesday, August 11, 2010

show ProgressBar while processing in background in ANDROID

AIM: To show progress bar while doing work in background thread like downloading image/vedio/response etc..

You can use AsyncTask   class which will do the background work in background thread while showing another UI(like progressbar,textview with loading or any other layout what ever you like) in UI thread.

You can do this by using the following code snippet.

Suppose you are downloading any thing from internet .here i am sending request to server and reading the response from the server.

The AsyncTask class which will does the background task.

       // ASync Task Begin to perform Billing information
private class performBackgroundTask extends Async Task < Void, Void, Void >  {

                private ProgressDialog Dialog = new ProgressDialog( this);

protected void onPreExecute() {
                       // here you have place code which you want to show in UI thread like progressbar or dialog or any layout . here  i am displaying a progressDialog with test please wait while loading......

                        Dialog.setMessage(" please wait while loading............");;


protected Void doInBackground(Void... params) {
 // write here the code to download  or any background task.
                         DownloadVideo();  // example call method which will download vedio .
return null;

protected void onPostExecute(Void unused) {
// the background task is completed .You can do the code here for next things



Call this method with the following line whereever you wants .for example like oncreate() or in anybutton handler as follows:
 new performBackgroundTask().execute();

Thats this way we can solve the problem.


  1. thanks,

    I wonder if we can change the progressdialog to a progressBar? Can you post an example for this?

  2. ProgressBar myProgressBar;
    int myProgress = 0;
    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {


    Log.d("SuccessfulScreen","Show progress bar and view button to view the content.");


    //set control made in XML
    Log.d("Progress bar", "Start count progress bar to 10");


    new Thread(myThread).start();

    Button btn = (Button) findViewById(;


    private Runnable myThread = new Runnable(){

    public void run() {
    // TODO Auto-generated method stub
    while (myProgress<10){
    Log.d("myProgress","myProgress count is " +myProgress);

    catch(Throwable t){
    Log.d("catch message","show message" + t.getMessage());
    //---hides the progress bar--- Runnable()
    public void run() {
    //---0 - VISIBLE; 4 - INVISIBLE; 8 - GONE---

    Log.d("successed message","message will show in textview");
    TextView textmsg = (TextView) findViewById(;
    textmsg.setText("The file is now saved to My Library which is located in the More category");
    Log.d("successed message","text nmessage" +textmsg.getText());
    Button btnview = (Button) findViewById(;
    //btnview.setEnabled(true); android:enabled="false"

    Handler myHandle = new Handler(){

    public void handleMessage(Message msg) {
    // TODO Auto-generated method stub

  3. This comment has been removed by the author.

  4. This comment has been removed by a blog administrator.

  5. I am getting the error at this line
    private ProgressDialog Dialog = new ProgressDialog( this);

    The Error is:
    The constructor ProgressDialog(AsyncTaskTest.performBackgroundTask) is undefined

  6. I didn't understand what your problem exactly.
    Probably,this 2 approaches may be useful for you.

    1)add the above declaration line in Oncreate() method.
    2)instead of
    new ProgressDialog( this);
    replace "this " with application context (or) classname.this.

    please check for any error that is happening in in BackgroundProcess like nullpointers,any exceptions.

  7. thanks. exactly what i was looking for :)

  8. Interestingly, a bit of these male enhancement devices and methods own been
    proved to be Flaccid and Raise states. This may look to elementary
    to really do work but sometimes elaboration is possible through the use of male enhancement.

    My weblog; site

  9. I don't know if it's just me or if everyone else experiencing problems with your site.
    It appears as if some of the text in your content are running off
    the screen. Can somebody else please provide feedback and let me know if this is
    happening to them as well? This could be a problem with my internet browser because I've had this happen previously. Many thanks

    Here is my web-site :: bonuses slots

  10. I know this if off topic but I'm looking into starting my own weblog and was curious what all is required to get set up? I'm assuming having a blog like
    yours would cost a pretty penny? I'm not very internet savvy so I'm
    not 100% certain. Any suggestions or advice would be greatly appreciated.

    Feel free to surf to my page: best enhancement reviews

  11. If some one needs to be updated with most up-to-date technologies
    after that he must be visit this website and
    be up to date every day.

    Also visit my page ... Genf20 plus

  12. I love what you guys are up too. This type of clever work and exposure!
    Keep up the wonderful works guys I've incorporated you guys to my own blogroll.

    my blog - super charge labrada

  13. I'm amazed, I have to admit. Seldom do I come across a blog that's equally educative and engaging, and without a doubt, you've hit the nail on the head. The problem is an issue that too few people are speaking intelligently about. Now i'm
    very happy that I came across this during my
    hunt for something relating to this.

    My website :: buy Total curve

  14. I am not positive the place you're getting your info, but good topic. I needs to spend a while studying much more or working out more. Thanks for excellent information I used to be in search of this information for my mission.

    Visit my weblog - venapro direction to use

  15. I get pleasure from, cause I discovered exactly what I used to be looking for.
    You've ended my 4 day long hunt! God Bless you man. Have a great day. Bye

    my web page: tinnitus control

  16. Excellent beat ! I wish to apprentice while you amend your web
    site, how could i subscribe for a blog web site? The account helped
    me a acceptable deal. I had been a little bit acquainted of this your broadcast provided bright
    clear idea

    Also visit my homepage ...

  17. Nice post. I was checking continuously this blog and
    I am inspired! Very useful info specially the final part :) I handle such info much.

    I used to be looking for this certain info for a long time.

    Thank you and best of luck.

    my page; proactol online

  18. I do trust all of the ideas you've offered in your post. They are very convincing and can certainly work. Nonetheless, the posts are too brief for newbies. May just you please lengthen them a bit from subsequent time? Thanks for the post.

    my blog ... capciplex

  19. This is a good tip especially to those new to the blogosphere.
    Brief but very accurate info… Thanks for sharing this one.
    A must read article!

    My blog post: %anchor_text%

  20. Hello There. I discovered your blog the use of msn. This is a very well written article.
    I will be sure to bookmark it and come back to learn extra of your helpful info.
    Thank you for the post. I'll definitely comeback.

    Feel free to surf to my web site:

  21. You can certainly see your enthusiasm in the
    article you write. The arena hopes for more passionate writers like you who are not afraid to mention how they
    believe. Always follow your heart.

    Also visit my web site ... start playing im netz

  22. Good wгite-up. I definitely apprecіatе this ѕite.
    Keep ωrіting!

    Also visit my web blοg - 500fаstcash.
    com (

  23. Thanks for finally writing about > "show ProgressBar while processing in background in ANDROID" < Liked it!

    Here is my web-site: book of ra free games online

  24. I have been browsing online more than 3 hours today, yet I never found
    any interesting article like yours. It is pretty worth enough for me.
    In my opinion, if all web owners and bloggers made good content as you did, the net will be much more useful than ever before.

    Stop by my web page: achat viagra boutique paris

  25. gucci bags online
    Heya i'm for the first time here. I came across this board and I find It truly useful & it helped me out a
    lot. I hope to give something back and help others like you helped

  26. De quelle manière acheter des bitcoins anonymement sur le réseau tout de

    My web blog; acheter bitcoin

  27. I'm pretty pleased to find this page. I want to to thank you for your time due to this wonderful read!!
    I definitely loved every part of it and i also have you saved as a favorite to look at
    new information in your web site.

    Stop by my webpage; voice cabling toronto (

  28. I was very pleased to discover this site. I wanted to thank you for your
    time due to this wonderful read!! I definitely enjoyed every bit of it and I have you
    book-marked to see new stuff in your web site.

    Stop by my web page :: hosting service free

  29. ӏt's an amazing piece of writing for all the web visitors; they will get benefit from it I am

    Review myy web site; how can i rebuild my rebuild credit after chapter 7

  30. Fruits like pears and prunes are high in fiber and so can naturally rectify bowel dysfunction.

    Here is my homepage ... senna

  31. Awesome! Its truly remarkable post, I have got much clear
    idea on the topic of from this article.

    Here is my webpage web traffic

  32. Quality articles or reviews is the important to invite
    the viewers to pay a quick visit the web page, that's
    what this website is providing.

    Here is my web site: dui lawyer portland or

  33. I visited many blogs however the audio feature for audio songs present at
    this site is really marvelous.

    For the best solution please jump over to this post: ()

  34. Hi, I read your blogs on a regular basis. Your writing style is awesome,
    keep doing what you're doing!

    Stop by my webpage Mansions at Acqualina Condo 17749 collins avenue Miami Beach

  35. Hey I know this is off topic but I was wondering if
    you knew of any widgets I could add to my blog that
    automatically tweet my newest twitter updates. I've been looking for a plug-in like this for quite some time and was hoping maybe you
    would have some experience with something like this. Please
    let me know if you run into anything. I truly enjoy
    reading your blog and I look forward to your new updates.

    Feel free to visit my blog; E Liquid ()

  36. It's interesting that many of the bloggers your tips helped to clarify a few things for me as well as giving... very specific nice content.Android Training in chennai |Best Android Training in Velachery | android development course fees in chennai

  37. 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


Android Developers Blog

Ram's shared items