我想在uithread睡覺時顯示ProgressDialog,以便直到來自服務器的數據恢復爲止,我的活動將不會顯示。我怎樣才能做到這一點?當uithread睡覺時顯示ProgressDialog?
0
A
回答
1
您可以使用Thread
,AsyncTask
,或Service
到在後臺加載數據,並與Handler
實現控制你ProgressDialog
。
The example in this post顯示如何使用線程進行登錄請求,同時顯示進度對話框。
使用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);
由於AsyncTask
是一個泛型類型,你可以指定參數類型爲您的喜好,所以它是從UI線程傳輸數據非常方便一個後臺線程和後面。
你對話的部分是隻有活動中的幾行:
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;
}
0
將您的網絡進程代碼移動到Thread
並獲得ProgressDialog
。當您完成網絡過程時,請撥打.start();
,然後撥打ProgressDialog.show();
,啓動您的網絡進程,通過Handler
從Thread.run()
停止ProgressDialog
。
0
你可以嘗試在烏拉圭回合線程進步dialoge這個代碼
ProgressDialoge PD = ProgressDialog.show(這一點,「請稍候...「,」檢索數據「,true,false);
1
此任務通常通過帶有進度對話框的AsyncTask來解決。看到這個article。
相關問題
- 1. ProgressDialog未在UIThread中顯示
- 2. 聽signalStrength當手機睡覺
- 3. 睡覺
- 4. ProgressDialog不顯示
- 5. progressDialog不顯示
- 6. 顯示ProgressDialog Android
- 7. 顯示ProgressDialog OnItemClick
- 8. ProgressDialog不顯示
- 9. 當從NSOperation調用UITableView睡覺
- 10. 的StackOverflowError顯示ProgressDialog
- 11. 在Android中搜索時顯示ProgressDialog
- 12. 在打開網站時顯示ProgressDialog
- 13. 從文件加載AppState時顯示ProgressDialog
- 14. 在服務啓動時顯示ProgressDialog
- 15. 如何在等待HttpRespons時顯示ProgressDialog?
- 16. 電話不睡覺?
- 17. 顯示progressdialog不顯示在asyctask
- 18. 蟒蛇,倒計時器,不睡覺
- 19. 在睡覺時執行一個動作
- 20. 在Solaris上睡覺時遇到SIGALRM 9
- 21. 在手機在睡覺時處理NFC
- 22. HealthKit - 顯示睡眠
- 23. ProgressDialog不顯示。再次
- 24. ViewPager片段不顯示ProgressDialog
- 25. 在PreferenceActivity中顯示ProgressDialog
- 26. 安卓:ProgressDialog不顯示
- 27. ProgressDialog沒有顯示 - Android
- 28. 的AsyncTask不顯示ProgressDialog
- 29. ProgressDialog顯示不正確的
- 30. 如何顯示在ProgressDialog