开发者

Android: How to make UI thread to wait till AsycTask completes

开发者 https://www.devze.com 2023-03-28 17:56 出处:网络
Currently, I\'m executing 开发者_JAVA百科a heavy task inside AsycTask which uploads images. When I do it via AsycTask, the application closes and no error message appear in the logcat.

Currently, I'm executing 开发者_JAVA百科a heavy task inside AsycTask which uploads images. When I do it via AsycTask, the application closes and no error message appear in the logcat.

    private class SendIncidentTask extends AsyncTask<Double, Void, Void>{

            @Override
            protected Void doInBackground(Double... params) {
                lat1 = params[0];
                log1 = params[1];
                SendingIncident sincident  = new SendingIncident();
                sincident.sendInciWithoutAttachment(lat1, log1);
                sincident.submitWithAttachment(lat1, log1);
                return null;
            }

   }

I think issues occur when the UI thread and AsycTask execute in parallel. How can I make the UI thread wait until the AsycTask finishes?

Thanks in advance.


Use onPostExecute method to load UI.This is automaically called after doInBackground is completed


I think you miss the real problem, and doing what you want will cause ANR. But if you want the UI thread to wait, just execute it as a method of the activity, and not as AsyncTask.

0

精彩评论

暂无评论...
验证码 换一张
取 消