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

Inside Services post / postRemote only post local #9

Open
paulgavrikov opened this issue Jun 10, 2015 · 8 comments
Open

Inside Services post / postRemote only post local #9

paulgavrikov opened this issue Jun 10, 2015 · 8 comments

Comments

@paulgavrikov
Copy link

Code works in Activities, but inside a service both post or postRemote only post to the local event listeners.

public class WearService extends Service {
    public WearService() {
    }

    @Override
    public void onCreate() {
        super.onCreate();
        EventBus.getDefault().register(this);
    }

    public void onEvent(Long i) {
        L.e("onEvent:long "+i);
        pushToWear();
    }

    public void onEvent(String s) {
        // called after pushToWear!!!!
    }

    private void pushToWear() {
     ...
        EventBus.getDefault().postRemote(payload.toString(), this);
    }
}
@paulgavrikov
Copy link
Author

Looks like, post / postRemote work only on the UI Thread, so assign a handler in onCreate of the Service (this is executed on the UI Thread) and then post Runnables with postRemote to it.

@tajchert
Copy link
Owner

Thanks for explanation.
I think this is EventBus issue/topic so If you feel the same please close issue as it is not directly BusWear related.

@paulgavrikov
Copy link
Author

Well, I don’t know theoretically you could build a workaround inside Wearbus.
But anyway I’d suggest you to write this down somewhere, nearly drove crazy to find out why it wasn’t working ;-)

On 10 Jun 2015, at 23:11, Michal Tajchert notifications@github.com wrote:

I think this is EventBus issue/topic so If you feel the same please close issue as it is not directly BusWear related.


Reply to this email directly or view it on GitHub #9 (comment).

@powder366
Copy link

Should not postRemote only post to remote? I have a case where it posts local, is this not a bug?
Update: This problem was the same as "paulgavrikov" had.

@paulgavrikov
Copy link
Author

It should but as you said it does not always work

Am 26 Aug 2015 um 23:53 schrieb powder366 notifications@github.com:

Should not postRemote only post to remote? I have a case where it posts local...


Reply to this email directly or view it on GitHub.

@tajchert
Copy link
Owner

postRemote is not guaranteed as it uses Messaging API (to speed up event propagation) instead of Data API but doesn't guarantees delivery (if for example watch loses connection, or is out of range).

@paulgavrikov
Copy link
Author

If it runs outside your Main Context it will go crazy. Check my issue in that

Am 27 Aug 2015 um 00:01 schrieb powder366 notifications@github.com:

Yes, but why does it end up local?


Reply to this email directly or view it on GitHub.

@powder366
Copy link

Im doing a postRemote within an onEvent and it seems that its treating my postRemote as already posting thus in postRemote "(!postingState.isPosting)", isPosting is "true", thus skipping it. So recursive posts is not possible, or?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants