Unregister Android Network Service Discovery services with abnormal app exits?

468 views Asked by At

I'm trying out the official android NSDchat example to communicate between two android phones connecting to the same wifi network.

The chatting part of the example was working fine. However, if the app exits abnormally, the onDestroy() method that unregisters NSD service cannot be called. For instance, a new instance of app is pushed to the phone while the app is running or the app is killed by task manager. When that happens, as a result, the Listener is lost and the already running service remains. If a new service is registered in the app, the name becomes 'name (2)'.

Do you think there is any way to remove these rouge services whose Listeners were lost? So far the only way that worked for me is restarting the phone.

I found similar discussion here but no conclusion: Android Network Service Discovery "timeout"?

Thank you very much!

0

There are 0 answers