Yarh
Yarh

Reputation: 4617

No subscribers for events posted from background service

I post EventBus.getDefault().post(new SendPlayer(player)); from a services, which is running in non main thread:

<service
  android:name=".player.PlayerService"
  android:process=":player"
  android:enabled="true"
  android:exported="true">
</service>

I expect to receive even in my fragment:

@Subscribe(threadMode = ThreadMode.MAIN) public void onEvent(SendPlayer event) {
  Log.w("mcheck", "onEvent");
}

However, I get message:
D/EventBus: No subscribers registered for event class yarh.com.tryexo.player.SendPlayer.

Events are delivered only if I remove android:process=":player".

Is it a bug or I misunderstood flow of posting events between background thread and main thread?

Upvotes: 2

Views: 232

Answers (1)

Kuffs
Kuffs

Reputation: 35661

The process attribute causes your PlayerService to run in its own separate process pretty much like a totally different app.

This is like trying to fire an event in one app from another totally different app. You will need to find a different way to communicate with your service or place all components that need to communicate in the same process.

Upvotes: 2

Related Questions