Listener already in use (Service Discovery)

后端 未结 3 2073
被撕碎了的回忆
被撕碎了的回忆 2021-02-04 06:07

I can\'t resolve one service while another is being resolved? If that\'s what the error means... What is the way to wait until it is resolved?

@Override
public v         


        
3条回答
  •  情话喂你
    2021-02-04 06:39

    You don't have to wait! If you look at the javadocs for resolveService(NsdServiceInfo serviceInfo, NsdManager.ResolveListener listener) here you'll notice that for the parameter listener it say's "to receive callback upon success or failure. Cannot be null. Cannot be in use for an active service resolution."

    Therefore in order for this to work just do the following:

    mNsdManager.resolveService(service, new MyResolveListener());
    

    Where MyResolveListener is:

    private class MyResolveListener implements NsdManager.ResolveListener {
            @Override
            public void onResolveFailed(NsdServiceInfo serviceInfo, int errorCode) {
                //your code
            }
    
            @Override
            public void onServiceResolved(NsdServiceInfo serviceInfo) {
                //your code
            }
        }
    

    hope this helps :)

提交回复
热议问题