Question

I am integrating both Volley and Otto in a project to handle all service calls and at the same time considering orientation changing. By using Otto i can unregister and re-register the bus on orientation change and then when the Volley returns a response i can then post back the result to the activity, this works perfectly. BUT i believe i have a gap that I have not yet handled and that is, What if i unregister my bus on pause, and then the response from volley is returned while the activity is still destroyed, volley then posts the response,(but no activity will get it), the activity is then resumed, bus is re-registered again and will receive not response since the broadcast has been already posted.

Is there any way to solve this? My first thought is to implement something like a how the Android sticky broadcast works? any other better ideas or thoughts?

Was it helpful?

Solution

If the activityids match, the actual APIResult is posted to the bus so the Activity can receive it like normal. If it doesn't match, then it is as if the event wasn't handled at all. For Otto, this results in a DeadEvent that wraps the Object that wasn't handled. APIService listens for DeadEvents and hangs on to ones containing an APIResult or APIResult.ActivityProxy. When an Activity registers to the bus, APIService posts all DeadEvents with the same activityid the bus so the Activity can receive the results.

Answer found here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top