【发布时间】:2018-10-23 23:22:28
【问题描述】:
我有一个包含进度条的片段。我在onCreateView() 方法中检索它,setVisibility() 工作正常。
现在,当我尝试在onActivityResult() 中设置相同进度条的可见性(在类级别的片段中声明)时,什么也没有发生。这是代码。
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data){
if(requestCode == REQUEST_CODE_PROFILE_VIDEO_PATH){
if(resultCode == Activity.RESULT_OK) {
String profileVideoPath = data.getExtras().getString(ProfileVideoRecordingActivity.VIDEO_PROFILE_PATH);
Log.d("DEBUG", profileVideoPath);
//Upload to server
File profileVideo = new File(profileVideoPath);
if(profileVideo.exists()) {
pbarVideoUpload.setVisibility(View.VISIBLE);
FireBaseWrapper fileUploader = new FireBaseWrapper();
String serverFolderPath = "videoprofile";
String contentType = "video/mp4";
FireBaseAfterUpload afterUpload = new FireBaseAfterUpload() {
@Override
public void onSuccess(String uploadURL) {
Log.d("DEBUG", "Successfully uploaded video to server");
Log.d("DEBUG", uploadURL);
pbarVideoUpload.setVisibility(View.GONE);
ProfileService profileService = new ProfileService(TAG) {
@Override
protected void onPreServiceCall() {
}
@Override
protected void onPostServiceCall() {
}
@Override
public void afterSuccess(Object object) {
ReturnCode successCode = (ReturnCode) object;
if(successCode.getSuccess()){
Log.d("DEBUG", "Profile Video URL updated in DB");
}else{
Log.d("DEBUG", "Profile Video URL NOT updated in DB");
}
}
@Override
public void afterError() {
Log.d("DEBUG", "Profile Video URL NOT updated in DB");
}
};
profileService.updateVideoPath(uploadURL);
}
@Override
public void onProgress(String data) {
}
@Override
public void onFaliure() {
Log.d("DEBUG", "Error! Didn't upload");
pbarVideoUpload.setVisibility(View.GONE);
}
};
try {
fileUploader.upload(profileVideo, profileVideo.getName(), serverFolderPath, afterUpload, contentType, false);
}catch (FileNotFoundException e){
Log.e("DEBUG", "FileNotFoundException", e);
}
}
}
}
}
我尝试在 Handler 内调用 setVisibility(),并在 UI 线程上使用 runOnUiThread()。两种方法都不起作用。
如何控制 Fragment 的onActivityResult() 内进度条的可见性?
我需要它,因为我正在onActivityResult() 中上传一个文件并且需要显示进度。
【问题讨论】: