Closed Ornolfr closed 8 years ago
Most likely you are doing long operation in main thread in onActivityResult callback. You can show progress in own activity. Just show progressbar immediately in onActivityResult and use any mechanism to perform this long operation in other thread (e.g.: java thread, AsyncTask etc.).
@lukaville Looks like I really changed the thread and it now returns to my activity immediately, but now it's not loading and showing progress at all.
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PICKFILE_REQUEST_CODE && resultCode == BaseActivity.RESULT_OK) {
final String filepath = data.getStringExtra(FilePickerActivity.RESULT_FILE_PATH);
new Thread(new Runnable() {
@Override
public void run() {
showLoading();
renderer.loadScene(new File(filepath));
hideLoadingAndShowUI();
}
});
}
}
Could you explain more concretely what I should do?
Thanks in avance.
You can't interact with UI in non-UI thread. showLoading() and hideLoadingAndShowUI() methods should be run in UI thread.
You can run code in UI thread using this method.
By the way, Java threads isn't good choice to perform background operations in Android. More preferable way is to use AsyncTasks or any other tools created to ease Android multithreaded programming.
Hello, In my app I am opening large obj files, so when I click on such file, the phone is lagging on the FilePickerActivity, and returns to my activity when my file is already opened. I assume that's actually not your problem or fault. Although I would be very appreciate if you implemented some mechanism such as progressView while the clicked file is being loaded OR to return to my activity immediately after it's clicked, so the process of loading is going there visually...
Thanks in advance.