Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The service cannot receive eventbus events. #703

Open
libq opened this issue Jul 13, 2022 · 1 comment
Open

The service cannot receive eventbus events. #703

libq opened this issue Jul 13, 2022 · 1 comment
Labels
more info required Needs more info to become actionable.

Comments

@libq
Copy link

libq commented Jul 13, 2022

MyService.java

@Override
public void onCreate() {
    super.onCreate();
    EventBus.getDefault().register(this);
}
@Override
public void onDestroy() {
    super.onDestroy();
    EventBus.getDefault().unregister(this);
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void onMyEvent(MyEvent event){
    Log.e(TAG,"onEvent");
}

MyFragment.java

EventBus.getDefault().post(new MyEvent());


manifast.xml

<application
    android:name="com.xxxx"
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme"
    android:usesCleartextTraffic="true"
    tools:ignore="GoogleAppIndexingWarning,UnusedAttribute">
  <service android:name=".MyService" />

=======================================================
ps1: MyFragment send the event after MyService started.
ps2: EventBus version : 3.1.1
android minSdkVersion 14
android targetSdkVersion 28

@greenrobot-team
Copy link
Collaborator

As the service listens on the main thread to the event, the event might get queued on the main thread event queue and not be delivered before the service is destroyed? And in general: does your code make sure the service is between the created and destroyed state?

Anyhow, this programming question is probably something to ask on Stack Overflow.

@greenrobot-team greenrobot-team added the more info required Needs more info to become actionable. label Jul 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
more info required Needs more info to become actionable.
Projects
None yet
Development

No branches or pull requests

2 participants