Android 中有两个常用的事件总线库,分别是 Otto 和 Green Robot 的 EventBus。网上有很多文章解释了如何在你的应用程序中应用它们。
Part 2 : 使用RxJava实现事件总线
我已经写了一个 demo 展示如何使用 RxJava : RxJava for Android in this github repo,而且我会继续完善这个 demo。下面看一下一些有趣的实现:
implement_bus_1.java
// this is the middleman object
public class RxBus {
private final Subject
现在,你有一个事件总线可以使用了。
下面是你如何将事件发布到总线中的方式: implement_bus_2.java
@OnClick(R.id.btn_demo_rxbus_tap)
public void onTapButtonClicked() {
_rxBus.send(new TapEvent());
}
这里是是你如何监听来自其他组件或服务的事件: implement_bus_3.java
// note that it is important to subscribe to the exact same _rxBus instance that was used to post the events
_rxBus.toObserverable()
.subscribe(new Action1() {
@Override
public void call(Object event) {
if(event instanceof TapEvent) {
_showTapText();
}else if(event instanceof SomeOtherEvent) {
_doSomethingElse();
}
}
});
在一些特殊场景下我们需要知道是否有订阅者在监听总线。例如,如果你使用事件总线来处理 GCM 通知推送,那么如果应用程序位于前台,则不希望发送推送通知,那么监听“ dead event ” 就显得很重要了。
例如,在最近发布的模块中,我们在我们的应用程序中添加了聊天功能。如果用户打开了应用程序(因此至少有1个或更多的订阅者监听着总线),我们不会发送推送通知,但是如果应用程序在后台,那么我们发送一个推送通知,让他们知道聊天消息。事件发布到事件总线后,如果没有订阅者正在监听,则返回 dead event 。如果我们收回一个 dead event ,就会发出一个推送通知。
在平时工作中,难免会遇到把 XML 作为数据存储格式。面对目前种类繁多的解决方案,哪个最适合我们呢?在这篇文章中,我对这四种主流方案做一个不完全评测,仅仅针对遍历 XML 这块来测试,因为遍历 XML 是工作中使用最多的(至少我认为)。 预 备 测试环境: AMD 毒龙1.4G OC 1.5G、256M DDR333、Windows2000 Server
Netty 3.x的user guide里FrameDecoder的例子,有几个疑问:
1.文档说:FrameDecoder calls decode method with an internally maintained cumulative buffer whenever new data is received.
为什么每次有新数据到达时,都会调用decode方法?
2.Dec
hive> select * from t_test where ds=20150323 limit 2;
OK
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
问题原因: hive堆内存默认为256M
这个问题的解决方法为:
修改/us
Simply do the following:
I. Declare a global variable:
var markersArray = [];
II. Define a function:
function clearOverlays() {
for (var i = 0; i < markersArray.length; i++ )
Quick sort is probably used more widely than any other. It is popular because it is not difficult to implement, works well for a variety of different kinds of input data, and is substantially faster t