简体   繁体   中英

Send data from a different Class to the main UI-Thread

could somebody tell me how I can send data from a different Class (not an High-level class eg not an Activity, Service ... etc) to the UI-Thread? To be more concrete in my App I have a class which connects to a server returning a JSONObject from a Thread. From that point I want to send back the JSON to the UI-Thread (My Activity). I've read something about Handler and Looper but this is very confusing for me specially because the most examples are based on the fact that the data transfer occurs in 2 Threads in the same Class. I would like to have the steps with a code snippet to know where and what I should implement. Thank you for helping

There is a specific Thread-implementation in Android for just that. The AsyncTask lets you do something on the UI-Thread before and after the execution in a background thread. It is mainly used for calculating something in the background and then updating the UI or to display some kind of dialog while the background thread works.

I find it fairly simple to use.

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