如何线程在Android的听众互动? [英] How do threads interact with listeners in Android?

查看:91
本文介绍了如何线程在Android的听众互动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个Android应用程序,我需要一些监听器(用于网络的变化,位置变化等)。

In an Android app, I need several listeners (for network changes, location changes, etc.).

据我所看到的,这些被称为一个线程(或线程),这是不是我的主要后台服务线程。 (我创建一个服务唯一的应用程序。)

As far as I can see, these are called in a thread (or threads) which are not my main background service thread. (I'm creating a service-only app.)

我的问题是:

可我的应用程序被监听器同时射击命中,还是Android的调用我的听众在单个线程缓解呢?

Can my app be hit by listeners firing simultaneously, or does Android mitigate this by invoking my listeners in a single thread?

其次,如果听众不'sequentialised',是个别的收听重入?

Secondly, if the listeners aren't 'sequentialised', are the individual listeners re-entrant?

在换句话说,我可以进行复杂的处理,我的听众,还是应该只转储发生了什么事到同步列表,以便进行后续处理我的后台服务线程(和从睡眠唤醒后台服务线程,而他们它)。

In other words, can I carry out complex processing in my listeners, or should they just dump what happened into a synchronized list, for later processing my background service thread (and wakeup the background service thread from its sleep while they're at it).

似乎是在Android的例如文档和书籍的线程同步很少报道。

There seems to be very little coverage of thread synchronisation in Android example docs and books.

谢谢

克里斯。

推荐答案

我不知道是什么类型的听众你在说什么特别的,但一般他们不叫上自己的线程。他们被称为您注册的侦听器线程,因此,如果您注册UI上的监听线程将火UI线程。如果您创建一个 尺蠖 线程,那么你就可以在该线程注册听众,他们将火在该线程顺序,因为他们打。

I don't know what types of listeners you're talking about specifically, but generally they are not called on their own threads. They are called on the thread that you register the listener on, so if you register the listener on the UI thread it will fire on the UI thread. If you create a Looper thread, then you can register listeners on that thread, and they will fire in that thread sequentially as they hit.

这篇关于如何线程在Android的听众互动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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