In an application I have an Activity
, a Service
(doing some stuff regardless of whether or not the activity is visible), and a Model class (in MVC sense), it is a singleton. The activity and the service play the role of Controllers, the View is defined in the xml layout (nothing custom, the existing classes are re-used). Both Controllers use the same Model. The service is not remote, that is, lives in the same process.
There are a number of techniques (e.g. here, here, here) recommended for communication between an Activity
and a Service
, common data structures are not among them (Google says it is possible, but that's in a section that does not even mention broadcasts, messengers, binding and other service-specific stuff). Well, I understand issues with multiple threads, but if I care about the access from multiple threads myself, why on Earth do I need other methods?
(UPD: I have checked, in fact, the service and the activity even use the same thread: "main", id=1.)
Question: Is the use of common data structures for communication between activities and services considered a bad style? If yes, why?
So far I am inclined to think that this method is a valid one.