Inter-Process Communication , Compile-time Annotation.
Apollo , make RxBus simplified but not simple.
quick integration with 3 minutes
use jitpack in your module.
allProjects {
repositories {
maven { url "https://www.jitpack.io" }
}
}
depend these in your build.gralde.
dependencies {
implementation "io.reactivex.rxjava2:rxandroid:2.0.1"
implementation "com.github.lsxiao.Apollo:core:1.0.2"
//IPC module,optional
implementation "com.github.lsxiao.Apollo:ipc:1.0.2"
annotationProcessor "com.github.lsxiao.Apollo:processor:1.0.2"
//for kotlin
kapt "com.github.lsxiao.Apollo:processor:1.0.2"
}
ApolloBinderGeneratorImpl
在编译时生成。
Apollo.init(AndroidSchedulers.mainThread(), this);
In order to avoid memory leaks, it should be bind and unbind within the component lifecycle.
public abstract class BaseActivity extends Activity {
private ApolloBinder mBinder;
@Override
protected void onCreate(Bundle savedInstanceState) {
...
mBinder = Apollo.bind(this);
}
@Override
protected void onDestroy() {
...
if(mBinder != null){
mBinder.unbind();
}
}
...
}
make emit easier.
Apollo.emit("event","hello apollo")
receive anywhere you like.
@Receive("event")
public void onEvent(String message){
...
}
default is closed.
Apollo.init(AndroidSchedulers.mainThread(), this,true);
your data object which need to ipc must has a non-parameter-constructor,because apollo used kory to serialize object.
more usage see below.
Notice!!!,The annotated function must be public, and @Receive is required ,others is optional.
annotation | parameter | description | default |
---|---|---|---|
@Receive | string tag list, or a string | ||
@Sticky | remove | is remove after receive event. | ture |
@SubscribeOn | subscribe on scheduler | SchedulerProvider.Tag.IO | |
@ObserveOn | observe on scheduler | SchedulerProvider.Tag.MAIN | |
@Take | how many times can be received. | ||
@Backpressure | backpressure strategy(BackpressureStrategy.BUFFER,BackpressureStrategy.DROP,BackpressureStrategy.LATEST) |
boolean sticky = true;
//only tag
Apollo.emit("tag");
//tag and object
Apollo.emit("tag","event");
//stikcy(can received event which is annotated by @Sticky)
Apollo.emit("tag","event",stikcy)
//only tag and stikcy
Apollo.emit("tag",sticky)
Apollo use kory to serialize object,you can override it by providing a serializer.
Apollo.serializer(new Serializable() {
@NotNull
@Override
public byte[] serialize(@NotNull Object obj) {
...
}
@Override
public <T> T deserialize(@NotNull byte[] data, @NotNull Class<T> clazz) {
...
}
});
-dontwarn com.esotericsoftware.kryo.**
-dontwarn org.objenesis.instantiator.**
-dontwarn org.codehaus.**
-dontwarn java.nio.**
-dontwarn java.lang.invoke.**
-keep class com.lsxiao.apollo.generate.** { *; }
- RxJava2 - Reactive Extensions for the JVM
- RxAndroid2 - Reactive Extensions for Android
welcome pr.
We use SemVer for versioning. For the versions available, see the tags on this repository.
- lsxiao - Android developer - lsxiao See also the list of contributors who participated in this project.
Apache License Version 2.0
- All I love, and who love me.