0

I'm making an app that uses Network Service Discovery, let's call it a "Wi-fi Chat". And at some point I want to unregister a service created earlier in order to avoid creation of countless copies of it. But the problem is, when I cal;

mNsdManager.unregisterService(mRegistrationListener); 

I get "listener is not registered" error. To make sure that I have STILL THE SAME object of that listener I even initialized it in a class that extends Application class and still I get this error. So, the question is: how to unregister a service properly? Thank you in advance.

Also, I looked through "NsdChat" sample application, and it crashes at the same point with the same error!

4

1 回答 1

0

嗯,我找到了一个解决方案。非常感谢修复 NsdChat Google 示例的向导。

解决方案是:在 tearDown() 方法中,我们调用 unregisterService(RegistrationListener listener) 我们应该这样做

public void tearDown() {
        if (mRegistrationListener != null) {
            try {
                mNsdManager.unregisterService(mRegistrationListener);
            } finally {
            }
            mRegistrationListener = null;
        }
    }

虽然我仍然不知道这实际上是如何工作的,所以如果您对这个难题有任何想法,请发表答案

于 2015-04-29T07:36:26.413 回答