如何让一个线程与另一个活动线程通信 [英] How to let a thread communicate with another activity thread

查看:96
本文介绍了如何让一个线程与另一个活动线程通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始学习android,我在我的项目中遇到问题

i'm beginning to learn android, i meet a problem in my project,

在我的应用程序中,我创建了一个后台线程,该线程通过UDP从远程服务器获取数据,
在此线程中,我将解析数据并将消息分发到不同的活动进行处理,因此我不知道天气是否存在处理此问题的机制.

in my application,i create a background thread which get data from remote server by UDP,
in this thread ,i will parse the data and distribute the message to different activity to process, so i don't know weather is there a mechanism to handle this problem.

感谢您的回答

推荐答案

您应该看一下有关

You should take a look at this article about painless threading in android, and pick a solution that best fits for you.

如果反复从服务器检索数据,也许应该使用Service-Handler解决方案,但是AsyncTask接缝对我来说是最简单的.

If you retrieve data from the server repeatedly, maybe you should go with a Service - Handler solution, but AsyncTask seams to be the easiest for me.

这篇关于如何让一个线程与另一个活动线程通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆