No need to make it so complicated.

Since you mentioned that your objects aren't parcelable -- we're talking
about sharing data between various places all within same process (VM).

You can just pass them around the way you normally would between methods /
classes.

To make it cleaned, I'd look into some kind of "event bus" where some
objects can subscribe to abstract "changes" and others can send these
"change notifications".

Can be something like JavaRX or an "event bus", for example:

http://greenrobot.org/eventbus/

( I haven't used this, but the principle is the same )

-- K


2016-02-04 21:40 GMT+03:00 Massimo Del Zotto <[email protected]>:

> Hello,
> In my program I need to pass 'live' Objects from one activity to another.
> Those are most likely not parcelable and most likely not just data. I
> figured out I could use a local Service to provide a cross-Activity data
> sharing. It's just a map from unique ids to Object. Initial
> experimentation went great.
>
> However, I am having serious trouble with a difference between the back
> and the up button.
>
> The application is set up as follows: there's a MainMenu Activity which
> launches the service by means of bindService(..., BIND_AUTO_CREATE).
> Other "inner" activities bind by bindService(..., 0). They unbind on
> onDestroy, mostly because I'm lazy.
>
> Now, because of the way I have setup activities, the up and the back
> buttons should be equivalent. And indeed they are. Sort of.
>
> When I push the back 'hardware' button I have: onPause, onStop, onDestroy as
> expected. Here, I de-register the callback and... at a certain point I got
> a huge error by pushing the 'back' button relating to a leaking window
> created in my onServiceDisconnect. Indeed, I show an error dialog when
> this happens with the only option being calling finish().
>
> I figured out I needed to keep track of unbinding status. It was my
> understanding onServiceDisconnect wouldn't get called when I
> unregister... it turns out the 'back' button produces this sequence of
> calls: onPause, onServiceDisconnected, onServiceConnected (MainMenu),
> onStop, onDestroy.
>
> *Is anyone aware of this difference and why does that happen?* As a side
> note, this implies Binders should be passed around (in MainMenu) with
> care as they can go stale. Not really a big problem but something to keep
> in mind.
>
> I'm trying to devise a solution. For the time being, I'll think I'll
> resolve to 'instant service connections' so I bind, do what I need and
> unbind right away. I might do that in an AsyncTask in case... *isn't that
> an hammer solution?* I totally missed about this difference in
> documentation and I'm confused on how to use services correctly at this
> point.
>
> Elaborations are welcome.
>
> Massimo
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Android Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/android-developers.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/android-developers/b7a759ba-2013-4669-81c3-28628c12b59a%40googlegroups.com
> <https://groups.google.com/d/msgid/android-developers/b7a759ba-2013-4669-81c3-28628c12b59a%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/android-developers/CAN7dqjAc8s35WsuAU8BX8%3DR3UWUjWRnpuZkAWa9jb3%2BwpSHo9Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to