简体   繁体   中英

How to execute the method with returned value from an asynctask?

A method is for Custom View, and Asnyctask B is for getting URL. To load an image on Custom View with returned URL from Asynctask, I need to execute Custom View method after the asynctask. When I call the method after asynctask, the method gets null because asynctask didnt return the value yet. How can I handle this problem?

customView= findViewById(R.id.custom_view);
UrlRequest urlRequest = new UrlRequest(this).build(); // AsyncTask
customView.loadImg(urlRequest); // null value

On Logcat, customView.loadImg method run first, then urlRequest is returned.

I expect the returned data, but the actual output is null...

Maybe check this out. It should work the same way as await does in c# . I am not completely sure tho

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM