Is it possible to post
event in one process (for example inside SyncAdapter
which has android:process=":sync"
manifest attribute) and receive it in another (inside regular app UI) with Otto or EventBus?
I know that Intent
and BroadcastReceiver
work just fine for communication across multiple processes but I would like to have simplicity and flexibility with Otto/EventBus.
No, that is not possible, as Otto, greenrobot's EventBus, and LocalBroadcastManager
are all in-process solutions.
You might consider simply removing the android:process
attribute from the manifest, so it all runs in one process.
No, but you can use transit. For example using BroadcastReceiver
: In one process, send a broadcast
with your data, then through the interior of BroadcastReceiver
onReceive
methods, post a otto event.
Like my codes:
public class ReceiveMessageBroadcastReceiver extends BroadcastReceiver {
public static final String ACTION_RECEIVE_MESSAGE
= "me.drakeet.xxxxxx.ACTION_RECEIVE_MESSAGE";
public static final String AGR_MESSAGE = "AGR_MESSAGE";
// this method can be called in other processes
public static void sendBroadcast(Context context, MessageContent content) {
Intent intent = new Intent();
intent.setAction(ACTION_RECEIVE_MESSAGE);
intent.putExtra(AGR_MESSAGE, content);
context.sendBroadcast(intent);
}
// this method will run in your default process, so you can post otto events to your
// default process
@Override public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action.equals(ACTION_RECEIVE_MESSAGE)) {
MessageContent content = intent.getParcelableExtra(AGR_MESSAGE);
Otto.getSeat().post(new PlayMessageReceivedEvent(content));
}
}
}
I know this question is a bit old, but there seems to be a library that claims it can handle a cross-process communication with an event-bus/Rx style architecture.
https://github.com/edisonw/PennStation
Disclaimer: I have not tried this, just found it and it claims to do what this question is asking.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With