ProgressDialog doesn't appear

后端 未结 2 610
慢半拍i
慢半拍i 2021-01-13 09:31

I have the following in my Activity that I use to download a users films in their LoveFilm queue, but the ProgressDialog never appears.

public class MyListAc         


        
相关标签:
2条回答
  • 2021-01-13 10:05

    What if you call with this instead of MyListActivity.this?

    It is possible, though unlikely since this is within onCreate(), that it is not being called from the UI thread.

    Try surrounding the call with runOnUiThread():

        Activity me = this;
        runOnUiThread(new Runnable()
        {
            public void run()
            {
                m_progressDialog = ProgressDialog.show(me, "Please Wait", "Loading", true);
            }
        });
    
    0 讨论(0)
  • 2021-01-13 10:08

    It's better if you use AsyncTask (instead of thread - it is generally good practice in Android activities).

    Create an AsyncTask class, and on that class add a progress dialog at onPreExecute, and dismiss it at onPostExecute. You can find an example here.

    Other than that, there are a few problems in your code:

    1. Calling ProgressDialog.show(...) at onCreate(...) is generally problematic (since you won't see it until onCreate will finish, which is usually way after your background activity has finished).
    2. All of the operations on your progress dialog should be executed only on the UI thread, so you can't use m_pd.dismiss() on some random thread (that's why you should use AsyncTask).
    0 讨论(0)
提交回复
热议问题