简体   繁体   中英

How can I create a thread that returns the results to multiple activities simultaneously?

I need help! I'm developing an app consists of two activity where the first activity starts the second. I need to run a thread exclusively in the second activity, which reads data from a server and displays them in the first activity and in the second. Specifically, if I have a situation where during the execution of the thread in the second activity, I press the back button to return to the first activity, the same thread must continue its execution without suspend him or lock up and give me back the real-time results that I can see in both activity.

Do you have any suggestions for me? Thanks in advance.

That's what Service is for. A Service can be started by the second Activity, but will exist even after the death of that Activity. The Thread should be owned by the service. The service can send a broadcast with the results, which both the first and second activities can listen for.

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