简体   繁体   English

将数据从线程发送到活动

[英]send data from a thread to an activity

I'm creating an app that is a sort of client- multithreaded server. 我正在创建一个类似于客户端多线程服务器的应用程序。

The problem that I'm facing with is the next one: 我面临的问题是下一个:

The server is multithreaded and that means that it receives the data from the clients in a thread(a separate class which is not a inner class for an activity) and I wanna send that data to a class that extends activity!!! 服务器是多线程的,这意味着它在线程(一个单独的类,不是活动的内部类)中从客户端接收数据,我想将该数据发送给扩展活动的类!

Is that possible?And if yes,how?? 那有可能吗?

Thank u! 感谢你!

UPDATE:My thread is a Worker thread it implements Runnable and the data needs to ne send to a different class that extends activity!!! 更新:我的线程是一个Worker线程,它实现了Runnable,并且需要将数据发送到扩展活动的其他类中!!!

Yes, you can send a Message from the thread back to the Activity using a Handler . 是的,您可以使用Handler将消息从线程发送回Activity。 This article may be helpful. 本文可能会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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