I'm using sticky events in EventBus to pass my "selected" objects into the upcoming Activity. The detail activity allows the user to "select" another object to fetch a new list. I want to post another sticky event with the same object class again into yet another list activity, but from what I understand, the previous sticky will get overwritten. See the example illustration at the bottom.
What is the recommend way around this problem? I need to have n-nested sticky events with the same class in EventBus.
I really like having sticky objects, it eliminated my need to hand-wire up the Android Parcelable interface just to send objects from one living activity to another with the Intent
mechanism. I'd hate to be forced to go and have to implement Parcelable even after getting a fully working EventBus just because I can't have nested sticky objects!
One way I thought up was to maintain my own stack of Item
objects in an ArrayList in a Singleton, pushing when diving deeper (before startActivity) and popping when backing out (but where? onDestroy
is not to be used), but the approach seems extremely fragile to me. I need a robust mechanism - this is the primary navigation pivot for my app.
- List of items, user selects an
Item
. We post a sticky event with thisItem
and startActivity with detail view class in Intent. - User browses through the detail and asks for a list of related items. We start another activity showing the list.
- User selects an
Item
. We post a sticky event with this secondItem
and startActivity with detail view class in Intent. The secondItem
overwrites the firstItem
and when the user wants to navigate up the back stack, it is no longer available to read, instead the last sticky item created is read.