开发者

android: IPC remove listener

I used this tutorial to create my own :remote service. It works, but with one problem: I can't remove listener. The trace is:

onServiceConnected add listener: net.ServiceGP$1@4493016开发者_JAVA百科8 

(from my main activity, when I do the following:

startService(i);
bindService(i, serviceConnection, 0);

Then form the service:

Adding new listener [net.bgtask.ServiceListener$Stub$Proxy@44916d30]... new listener size = 1

Then I press back button and:

onDestroy of main activity, removing listener: net.ServiceGP$1@44930168

And form the service:

Removing listener   [net.bgtask.ServiceListener$Stub$Proxy@44917440]... new listener size = 1

Weird...In activity I have the same object, but in the service different ones. WHY so?


Problem in this example (compare link) is that a list is used for the listener collection

private List<TweetCollectorListener> listeners = new ArrayList<TweetCollectorListener>();

instead of

private RemoteCallbackList<TweetCollectorListener> listeners = new RemoteCallbackList<TweetCollectorListener>();

with the corresponding

(1) listeners.register(listener);
(2) listeners.unregister(listener);

instead of

(1) listeners.add(listener);
(2) listeners.remove(listener);

The argument (seem to me) not to be reference to the same Listener, but RemoteCallbackList handles this problem.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜