1. Download our Official Android App: Forums for Android!

Apps Cannot get ProgressDialog to display in Thread

Discussion in 'Android Development' started by RazzleFnDazzle, Apr 6, 2011.

  1. RazzleFnDazzle

    RazzleFnDazzle Well-Known Member
    Thread Starter
    Rank:
    None
    Points:
    58
    Posts:
    123
    Joined:
    Sep 30, 2010

    Sep 30, 2010
    123
    15
    58
    Well I've seen a wide variety of failures while trying to get this to work. I have a thread that is started via an Activity. The thread needs to create/display progress dialogs and dismiss them.

    When I tried to directly display the ProgressDialog I got an error that my Looper wasn't prepared. I looked up with a Looper was an implemented it. However, I had to call Looper.loop for the progress dialog to show up. After it showed up the application froze on that point never to continue past the Looper.loop call.

    I couldn't get it to work so looked for a whole new way using a HandlerThread and a Handler. I create a HandlerThread and start it. I get the looper from the thread and create a Handler with it. My ProgressDialog or Toasts won't show up at all.

    Is there an easier way to go about doing this?
     

    Advertisement

  2. JamTheMan

    JamTheMan Well-Known Member
    Rank:
    None
    Points:
    38
    Posts:
    136
    Joined:
    Dec 16, 2010

    First of all, all UI stuff must be handled by the UI (main) thread in Android! That's the main reason you need all the handlers and stuff...

    The only other way to do it is by implementing a AsyncTask, that works like a Thread, but handles the communication with the UI thread to make it all happen...

    You can look into it here:

    AsyncTask | Android Developers
     
    RazzleFnDazzle likes this.
  3. RazzleFnDazzle

    RazzleFnDazzle Well-Known Member
    Thread Starter
    Rank:
    None
    Points:
    58
    Posts:
    123
    Joined:
    Sep 30, 2010

    Sep 30, 2010
    123
    15
    58

    Okay. I was thinking I needed to do that, but I wasn't sure. I gave it a shot, but I had the Thread already written. I'll have to refactor it out just for the dialog! I was afraid of that! Thank you.
     
  4. RazzleFnDazzle

    RazzleFnDazzle Well-Known Member
    Thread Starter
    Rank:
    None
    Points:
    58
    Posts:
    123
    Joined:
    Sep 30, 2010

    Sep 30, 2010
    123
    15
    58
    Okay for anyone who is looking for this same issue I solve my problem by simply initializing my Handler.Callback inside the actually activity and passing it to the thread.
     

Share This Page

Loading...