Exchange objects between Activity and Service
I have an Activity "A" which instantiates two objects from the Facebook Android SDK. I put these two objects into a static HashMap with unique static keys and their referen开发者_如何学Pythonces. From other activities "B" and "C" I'm able to get these two corresponding references via myhashmap.get()
. These two Activities are within the same application. So far so good.
Within Activity "A" I start a Service also part of the same application. My problem is that I now want to get access to my two objects stored in the static HashMap of Activity "A" but the HashMap is empty?!?
So my question how can I get access to objects which were created by my Activity "A" from my service ?
Any tips are more than welcome
I put these two objects into a static HashMap with unique static keys and their references.
That is not a recommended technique in Java.
Within Activity "A" I start a Service also part of the same application. My problem is that I now want to get access to my two objects stored in the static HashMap of Activity "A" but the HashMap is empty?!?
Remove the android:process="remote"
attribute from your manifest, if it is there -- you do not need it, you really do not want it, and it would cause this phenomenon.
So my question how can I get access to objects which were created by my Activity "A" from my service ?
Put the objects in the service in the first place, and have your activities get them from the service using the local binding pattern.
精彩评论