Android 是否在uithread睡眠时显示ProgressDialog?
我希望在uithread睡眠时显示ProgressDialog,以便在检索服务器数据之前不会显示我的活动。如何执行此操作?将网络进程代码移动到Android 是否在uithread睡眠时显示ProgressDialog?,android,Android,我希望在uithread睡眠时显示ProgressDialog,以便在检索服务器数据之前不会显示我的活动。如何执行此操作?将网络进程代码移动到线程中,并获得一个进程对话框。通过调用.Start(),启动网络进程
线程中
,并获得一个进程对话框
。通过调用.Start(),启动网络进程然后是ProgressDialog.show()
完成网络进程后,通过处理程序停止进程对话框
,从线程运行()
您可以使用线程
、异步任务
或服务
在后台加载数据,并使用处理程序
实现控制您的进度对话框
显示如何使用线程进行登录请求,同时显示进度对话框
使用AsyncTask
更简单、更清晰:
private static final int WAIT = 11;
private final class MyTask extends AsyncTask<Void, Void, Void>
{
@Override
protected void onPreExecute()
{
super.onPreExecute();
// Show up the dialog with id=WAIT [11]
showDialog(WAIT);
// other actions that must be performed in the UI thread
// before the background works starts
}
@Override
protected Void doInBackground(Void... params)
{
// perform the background work
return null;
}
@Override
protected void onPostExecute(Void result)
{
super.onPostExecute(result);
// Remove the dialog with id=WAIT [11]
removeDialog(WAIT);
// other actions that must be performed in the UI thread
// after the background works finished
}
}
[...]
final MyTask task = new MyTask();
task.execute(null);
您可以在您的线程中为进度对话框尝试此代码
ProgressDialoge pd=ProgressDialog.show(这是“请稍候…”,“正在检索数据”,true,false) 此任务通常使用AsyncTask解决,AsyncTask与progress对话框绑定。看这个
private ProgressDialog dialog;
@Override
protected Dialog onCreateDialog(int id)
{
switch (id)
{
case WAIT:
{
dialog = new ProgressDialog(this);
dialog.setMessage("Loading...");
dialog.setIndeterminate(true);
dialog.setCancelable(true);
return dialog;
}
}
return null;
}