Cedulio Cezar
Cedulio Cezar

Reputation: 298

Otto - post a message between activity lifecycle

I'm studying a way to handle activity lifecycle and retain the state/progress of users app, then I found the otto/eventbus solution.

But after some research i can't figure out how to handle a particular case. So, what happens if my worker thread (async) finishes between the onpause/oncreate of my activity/fragment, it won't deliver the data? I'm trying to find an answer or create a project to test this, but just with my tests i can't be sure.

Am I missing something or the bus won't deliver the data? If it won't deliver the result how to handle that?

Sorry for my awful english.

Upvotes: 1

Views: 457

Answers (1)

laalto
laalto

Reputation: 152847

Events are only passed to subscribers that are active at the time of posting.

To deliver an event to subscribers later on, store the object you're posting to a model object of sorts and add a @Produce getter for it. When a new subscriber for that object is registered, it gets its initial event from this @Produce getter.

Upvotes: 1

Related Questions