All Projects → ajgarn → mpeventbus

ajgarn / mpeventbus

Licence: Apache-2.0 license
Android event bus for multiple processes. Send and receive events within or between Android processes.

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to mpeventbus

Router
Router —— A substitute good of EventBus similar implemented by dynamic proxy
Stars: ✭ 147 (+950%)
Mutual labels:  eventbus
Liveeventbus
📬EventBus for Android,消息总线,基于LiveData,具有生命周期感知能力,支持Sticky,支持AndroidX,支持跨进程,支持跨APP
Stars: ✭ 3,192 (+22700%)
Mutual labels:  eventbus
rabbitmq-advanced-spring-boot-starter
A generic library for messaging with rabbit mq with extension on spring boot amqp
Stars: ✭ 85 (+507.14%)
Mutual labels:  eventbus
Eventbus
eventbus实现跨进程通讯方案
Stars: ✭ 153 (+992.86%)
Mutual labels:  eventbus
Bus
🔊Minimalist message bus implementation for internal communication
Stars: ✭ 187 (+1235.71%)
Mutual labels:  eventbus
KDispatcher
Simple and light-weight event dispatcher for Kotlin
Stars: ✭ 64 (+357.14%)
Mutual labels:  eventbus
Eventbus
C# 事件总线实现
Stars: ✭ 127 (+807.14%)
Mutual labels:  eventbus
Farseer.Net
Provides consistent standard use of common components of the .Net Core language
Stars: ✭ 42 (+200%)
Mutual labels:  eventbus
Unpeek Livedata
LiveData 数据倒灌:别问,问就是不可预期 - Perfect alternative to SingleLiveEvent, supporting multiple observers.
Stars: ✭ 208 (+1385.71%)
Mutual labels:  eventbus
evon
Fast and versatile event dispatcher code generator for Golang
Stars: ✭ 15 (+7.14%)
Mutual labels:  eventbus
Elegantbus
🔥🔥Android 平台,基于LivaData的EventBus,无侵入,更优雅,支持跨进程,跨应用粘性事件,自定义事件等功能。
Stars: ✭ 156 (+1014.29%)
Mutual labels:  eventbus
Messagebus
A MessageBus (CommandBus, EventBus and QueryBus) implementation in PHP7
Stars: ✭ 178 (+1171.43%)
Mutual labels:  eventbus
IntroduceToEclicpseVert.x
This repository contains the code of Vert.x examples contained in my articles published on platforms such as kodcu.com, medium, dzone. How to run each example is described in its readme file.
Stars: ✭ 27 (+92.86%)
Mutual labels:  eventbus
Eventbus
A lightweight and very fast event bus / event framework for C++17
Stars: ✭ 149 (+964.29%)
Mutual labels:  eventbus
green-annotations
An Android Annotations plugin to support Green Robot.
Stars: ✭ 21 (+50%)
Mutual labels:  eventbus
Androideventbus
[DEPRECATED] A lightweight eventbus library for android, simplifies communication between Activities, Fragments, Threads, Services, etc.
Stars: ✭ 1,597 (+11307.14%)
Mutual labels:  eventbus
azeroth-event
Lightweight event-driven framework
Stars: ✭ 18 (+28.57%)
Mutual labels:  eventbus
Retrofit-with-EventBus
Retrofit With EventBus
Stars: ✭ 21 (+50%)
Mutual labels:  eventbus
RxBus
🍾 标签/线程/Kotlin/自动注销的RxBus
Stars: ✭ 25 (+78.57%)
Mutual labels:  eventbus
AndroidStarterAlt
A sample View-based Android app using the MVP architecture. It uses Mosby, Dagger2, RxJava, retrofit, LoganSquare, requery, EventBus, Conductor.
Stars: ✭ 27 (+92.86%)
Mutual labels:  eventbus

MPEventBus - Multi-Process EventBus

Note: This project is under development and has not been finalized yet.

MPEventBus is an extension to greenrobot/EventBus that lets you send events between processes in your Android application.

In greenrobot/EventBus, you can send arbitrary events that your classes subscribed to the event bus receive. MPEventBus can, in addition, send events via Intents and listen to events from other processes via BroadcastReceivers, which delegate all received events to the EventBus instance running on the current process.

In order to send an event object between processes, the object must be either Serializable, Parcelable, a Bundle or a string.

Usage

Initialization

To initialize MPEventBus you must call the following method from your Application class's onCreate().

MPEventBus.init(getApplicationContext());

If you don't have an Application class yet, create one in your package root.

public class App extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        MPEventBus.init(getApplicationContext());
    }
}

Get the EventBus

From anywhere in your app you can get the MPEventBus instance by

MPEventBus mpEventBus = MPEventBus.getDefault();

Send a message

The process of sending a message is very similar to greenrobot/EventBus.

(1) Create an event class.

public class CustomEvent implements Serializable {/* Optional body */}

(2) Register objects as listeners.

mpEventBus.register(this);

And declare the method that should receive the event.

@Subscribe
public void onEvent(CustomEvent event) {/* Do something */};

(3) Send a message to all your processes, including the current one:

mpEventBus.postToAll(new CustomEvent());

Or send a message only to the current process (this is the same as using EventBus.post(...)).

mpEventBus.post(new CustomEvent());

Wake up process by event

By default, all running processes listen to your events. If you want a specific process to wake up when an event is sent you must register a BroadcastReceiver in your AndroidManifest.xml for that process.

Add the following to your AndroidManifest.xml, where you replace ":process-name" with the name of the process you want to be started on between-process events.

<receiver android:name="se.ajgarn.mpeventbus.MPEventReceiver" android:process=":process-name" android:exported="false">
    <intent-filter>
        <action android:name="multi_process_event" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</receiver>

Note that this broadcast will wake up the process for all events sent with the method mpEventBus.sendToAll(...).

Combine with EventBus

You can use EventBus and MPEventBus at the same time, since MPEventBus delegates to the EventBus instance. In other words, calls to the EventBus.getDefault() instance will work as they did before. In those cases you want to send events between processes, you need to make sure that the event object is either Serializable, Parcelable, a Bundle or a string. Then, initialize MPEventBus as described in the steps above.

Other

Feel free to send pull requests if you want to improve anything.

License

Copyright © 2016-2017 Anton Jansson

The project is released under the Apache License, Version 2.0

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].