I know there's simple mechanism to pass object between activities.
I usually use Bundle and putParcelable() or put Serializable(), but I know that it's actually passing raw data by packing and unpacking objects, without keeping references.
But now my problem is different - I need to pass reference to some services and other activities. Is there any way do do it?
Maybe I explain my issue on real problem:
City, which stores among other things weather data.ListFragment and display it there.GoogleMap, which shows Cities on list with weather.How should I store cities: List<City> in my application?
I need to pass reference to some services and other activities
No, you do not. You need to allow "some services and other activities" to have access to the same data. Passing by reference would be one way to achieve this end, but it is an approach not generally used in Android, just as it is not generally used in a Web app (pages do not pass JavaScript objects to other pages, for example).
The typical approach is to have a central data model, such as a singleton managing a bunch of POJOs, backed by a database. Then, you are passing identifiers around in Android, and those identifiers are usually simple values (ints, strings, etc.).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With