IPC on Android using GreenRobot clipboard

I need to contact a remote service using (greenrobot) EventBus. Unfortunately, it does not work with IPC. Looking at the code, I also do not see a workaround. Any help would be appreciated!

Bonus question - are there other EventBuses (for Android) that support IPC?

+7
android greenrobot-eventbus
source share
3 answers

I need to contact the remote service using the (greenrobot) EventBus.

The entire greenrobot EventBus dot, such as Square Otto and LocalBroadcastManager , is designed to not use IPC.

Any help would be appreciated!

Do not use greenrobot EventBus for IPC. Use one of the countless IPC mechanisms for IPC:

  • startActivity()
  • startActivityForResult()
  • startService()
  • bindService()
  • sendBroadcast() and its variations (e.g. sendOrderedBroadcast() )
  • a ContentProvider
+7
source share

There is an IPC EventBus option that allows you to send events through IPC. https://github.com/NewtronLabs/IpcEventBus

According to the documentation, all you have to do to get the event is the following:

 public class Listener implements IIpcEventBusConnectionListener, IIpcEventBusObserver { public Listener() { String targetApp = "com.packagename"; IIpcEventBusConnector connector = ConnectorFactory.getInstance().buildConnector(context, this, targetApp); connector.startConnection(); } @Override public void onConnected(IIpcEventBusConnector connector) { connector.registerObserver(this); } @Override public void onEvent(IEventIpc event) { Log.d("ipceventbus", "Received event: " + event.getClass()); } @Override public void onDisconnected(IIpcEventBusConnector connector) { } } 

And on the other hand, you post the event as follows:

 IpcEventBus.getInstance().postEvent(new MyEvent()); 

I created two applications, and they were able to send events to each other.

+5
source share

Another library that follows EventBus syntax is HermesEventBus. It supports IPC (and inside the process).

Although they were just to get from the EventBus, so we can just enter an EventBus object (which is actually a HermesEventBus), and we don’t have to update the code everywhere. https://github.com/eleme/HermesEventBus

0
source share

All Articles