等到异步任务完成其工作任务、工作

2023-09-05 05:22:05 作者:时光毁爱

我很新的节目,我有一些疑问。

我有一个的AsyncTask 这就是我所说的 RunInBackGround

和我开始这个过程中,如:

 新RunInBackGround()执行()。
 

不过,我想等到这个调用完成其执行,继续为code中的其他语句之前。

我怎么能这样做?

还有什么办法呢?

解决方案   

等待,直到这一呼吁是完成其执行

ü将需要调用AsyncTask.get()方法得到结果返回,并等待,直到doInBackground执行不彻底。但是的这将冻结主UI线程,如果你不打电话获得一个线程里面的方法的。拿到结果早在UI线程启动的AsyncTask为:

 字符串str_result =新RunInBackGround()执行()得到()。
 
OpenResty工作原理

I'm very new to programming and I have some doubts.

I have a AsyncTask which is I call as RunInBackGround.

and I start this process like:

new RunInBackGround().execute();

But I wish to wait until this call is finish its executing, before proceeding to the other statements of code.

How can I do that?

Are there any way for it?

解决方案

wait until this call is finish its executing

u will need to call AsyncTask.get() method for getting result back and make wait until doInBackground execution is not complete. but this will freeze Main UI thread if you not call get method inside a Thread. to get result back in UI Thread start AsyncTask as :

String str_result= new RunInBackGround().execute().get();

 
精彩推荐
图片推荐