开发者

A few questions about ProgressDialog in Android

开发者 https://www.devze.com 2023-02-24 07:26 出处:网络
1) FOA PD (ProgressDialog) can be created only from Activity, doesn\'t it? Please provide an useful example if it is really not.

1) FOA PD (ProgressDialog) can be created only from Activity, doesn't it? Please provide an useful example if it is really not.

2) If a PD should be created in separate thread could it be created and showed if it's thr开发者_StackOverflowead doesn't do anything at all? I mean something like this (assuming mProgressDialog is a property of the class):

new Thread(){
      public void run(){
          mProgressDialog = ProgressDialog.show(appContext, 
                  appContext.getResources().getString(R.string.progress_wait), 
                  appContext.getResources().getString(R.string.progress_db_installing), 
                  true);

  }.start();

As I understand the thread dies immediately after executing run() cause there is nothing to do and so PD doesn't show. It should have some processing code or at least an empty cycle with some manageable condition

3) if PD should be created in the main thread should it be created only at the end of OnCreate() method or in the body of some method called/caught(by some Listener) started in OnCreate() method?

4) PD by itself doesn't suspend any thread while displaying, does it? So the code continues executing after the show() method . I mean the show() by itself doesn't suspend/pause the thread cause I guessed it does.


1) Not sure how it's relevant unless you can come up with a reason to create a ProgressDialog outside of an Activity context; I think the answer is "no," though.

2) No, you can't create a dialog from a background thread directly. Have you tried your code? It'll die with an exception with a helpful traceback. See any one of a number of SO questions about how to call back to the UI thread to do things like show dialogs.

3) You can create it anywhere in your activity; for example, it's common to do this in onPreExecute() in an AsyncTask, which may be triggered from an onClick callback.

4) No.

0

精彩评论

暂无评论...
验证码 换一张
取 消