如何在 UI 线程上显示 ProgressDialog
鉴于 uploadPhoto,我真的一直在努力弄清楚如何在 UI 线程上获取此代码的 ProgressDialog,并且希望得到任何指导:
@Override
/** Handle Upload a Photo **/
protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
// Get image
if (resultCode == RESULT_OK) {
// ProgressDialog dialog = ProgressDialog.show(this, "", "Uploading Photo...", true, false);
switch(requestCode) {
// Take Photo
case 4001:
// Upload
uploadPhoto(Uri.fromFile(mImageFile));
break;
// Select Photo
case 5001:
// Get image
Uri selectedImage = imageReturnedIntent.getData();
// Upload
uploadPhoto(selectedImage);
break;
}
// Dismiss
// dialog.dismiss();
}
}
I have really been struggling figuring out how to get a ProgressDialog on the UI Thread for this code given that uploadPhoto and would appreciate any guidance:
@Override
/** Handle Upload a Photo **/
protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
// Get image
if (resultCode == RESULT_OK) {
// ProgressDialog dialog = ProgressDialog.show(this, "", "Uploading Photo...", true, false);
switch(requestCode) {
// Take Photo
case 4001:
// Upload
uploadPhoto(Uri.fromFile(mImageFile));
break;
// Select Photo
case 5001:
// Get image
Uri selectedImage = imageReturnedIntent.getData();
// Upload
uploadPhoto(selectedImage);
break;
}
// Dismiss
// dialog.dismiss();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 AsyncTask 类似这样:
并在您的
Activity
中这样调用它:Use AsyncTask something like this way:
and in your
Activity
call it like this way:使用AsyncTask也可以。将上传照片功能放在异步任务的后台。
在预执行中启动进度对话框。
执行后关闭/取消进度对话框。
后执行和预执行在 UI 线程上运行。
调用 asyncTask 使用
use AsyncTask may be. put the upload photo function in background of the async task.
start a progress dialog in pre execute.
dismiss/cancel progress dialog in post execute.
post execute and pre execute run on UI thread.
to call the asyncTask use