简体   繁体   English

有关Android中ProgressDialog的几个问题

[英]A few questions about ProgressDialog in Android


1) FOA PD (ProgressDialog) can be created only from Activity, doesn't it? 1)FOA PD(ProgressDialog)只能通过Activity创建,不是吗? 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 thread doesn't do anything at all? 2)如果应该在单独的线程中创建PD,可以创建它并显示它的线程根本不执行任何操作吗? I mean something like this (assuming mProgressDialog is a property of the class): 我的意思是这样的(假设mProgressDialog是该类的一个属性):

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. 据我了解,线程在执行run()之后立即死亡,因此无需执行任何操作,因此PD无法显示。 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? 3)如果应该在主线程中创建PD,应该仅在OnCreate()方法的末尾还是在OnCreate()方法中启动的/被某些侦听器捕获的某些方法的主体中创建PD?

4) PD by itself doesn't suspend any thread while displaying, does it? 4)PD本身不会在显示时挂起任何线程,对吗? So the code continues executing after the show() method . 因此,代码在show()方法之后继续执行。 I mean the show() by itself doesn't suspend/pause the thread cause I guessed it does. 我的意思是show()本身不会暂停/暂停线程,因为我猜想是的。

1) Not sure how it's relevant unless you can come up with a reason to create a ProgressDialog outside of an Activity context; 1)除非能提出在Activity上下文之外创建ProgressDialog的理由,否则不知道它的相关性; I think the answer is "no," though. 我认为答案是“不”。

2) No, you can't create a dialog from a background thread directly. 2)不,您不能直接从后台线程创建对话框。 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. 请参阅有关如何回调UI线程以执行诸如显示对话框之类的众多SO问题之一。

3) You can create it anywhere in your activity; 3)您可以在活动的任何地方创建它; for example, it's common to do this in onPreExecute() in an AsyncTask , which may be triggered from an onClick callback. 例如,通常在AsyncTask onPreExecute()中执行此AsyncTask ,这可能是通过onClick回调触发的。

4) No. 4)没有

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM