Based on my experience, I believe this is a lifelong listener problem.
Since you are supplying two listeners to the NSD service of the system, one for startServiceDiscovery () and one for stopServiceDiscovery (). you need to make sure that these listeners are still alive when the system addresses these listeners.
One of the facts is that onStartDiscoveryFailed () is called 2 minutes after the startServiceDiscovery () call, this should be a long time compared to the listener lifetime.
So, if the listener is a local object and is freed after calling startServiceDiscovery (), this may cause the NSD service to fail.
public void stopServiceDiscovery (NsdManager.DiscoveryListener Listener)
Disable service discovery initiated with findServices (). Active service discovery is reported to the application with onDiscoveryStarted (String), and it remains active until the application causes a service stop detection. A successful stop is notified with a call to onDiscoveryStopped (String).
After service discovery is denied, the application is notified via onStopDiscoveryFailed (String, int).
Listener Parameters This must be a listener object that was passed in to find the services (String, int, NsdManager.DiscoveryListener). This identifies the discovery that needs to be stopped and notifies a successful stop.
and below the snippet make sure you are not calling the NsdManager api.
@Override public void onStartDiscoveryFailed(String serviceType, int errorCode) { Log.i(TAG, "onStartDiscoveryFailed : Error code:" + errorCode); } @Override public void onStopDiscoveryFailed(String serviceType, int errorCode) { Log.i(TAG, "onStopDiscoveryFailed : Error code:" + errorCode); }
Good luck.
Zephyr
source share