Building an android app that displays a list of of Dog
objects in Activity A
. When you a tap a Dog
in the list, that single dog is accessed by Activity B
, Fragment B
, and 3 other classes.
After that Dog
is modified, it gets passed to Activity C
and Activity D
that all modify it, before finally making a network request.
Currently, I pass the same instance of Dog
back and forth through activities, fragments, and classes using callbacks, parcelable extra in intents, and bundles for fragments. This is getting really messy really fast. Is using a Singleton a good idea in this situation?
If Dog
were a singleton, how can I load multiple Dog
s to begin with?
Think of the list of Dog
s as a list of empty boxes. After a single Dog
is selected, it goes through a conveyer belt of Activities, Fragments, and helper Classes, where the box gets filled with data. At the end of the user flow, this box is filled up with a bunch of information, ready to be shipped off to the backend server.
Dog
before you have all the information you need to complete it. A better solution would be to build the components yourDog
consists of first, sayHairstyle
,TailWagglingMode
,TongueDrippiness
,... that you construct in your activities, and once you've got everything you need, you wrap it all up in aDog
.