开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜