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.
精彩评论