title: WiFiDirect discoverServices keeps failing with error 3 (NO_SERVICE_REQUESTS)
body: <p>I'm using WiFi P2P for <a href="http://developer.android.com/training/connect-devices-wirelessly/nsd-wifi-direct.html" rel="noreferrer">network service discovery</a>, and I'm following the instructions as outlined on the developer guide. Here's the relevant code in my service class:</p>
  
  <pre class="lang-java prettyprint-override"><code>public void onCreate() {
      manager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE);
      channel = manager.initialize(this, getMainLooper(), null);
      registerP2pService();
      lookForServices();
  }
  
  private void registerP2pService() {
      WifiP2pDnsSdServiceInfo serviceInfo =
              WifiP2pDnsSdServiceInfo.newInstance("_service.name", "_presence._tcp", new HashMap&lt;String, String&gt;());
  
      manager.addLocalService(channel, serviceInfo, new WifiP2pManager.ActionListener() {
          @Override
          public void onSuccess() {
              Log.i("tag", "REGISTERED SERVICE");
          }
  
          @Override
          public void onFailure(int arg0) {
              Log.e("tag", "FAILED to register service");
          }
      });
  }
  
  private void setServiceListeners() {
      WifiP2pDnsSdServiceRequest serviceRequest = WifiP2pDnsSdServiceRequest.newInstance();
      manager.addServiceRequest(channel, serviceRequest,
          new WifiP2pManager.ActionListener() {
          @Override
          public void onSuccess() {
              Log.d("SCOPE", "Added a service request.");
              discoverServices();
          }
  
          @Override
          public void onFailure(int code) {
              Log.e("tag", "Error adding service request.");
          }
     });
  }
  
  
  public void discoverServices() {
      manager.discoverServices(channel, new WifiP2pManager.ActionListener() {
  
          @Override
          public void onSuccess() {
              Log.d("tag", "Service discovery was initiated");
          }
  
          @Override
          public void onFailure(int code) {
              // This is where it keeps failing with error code 3 (NO_SERVICE_REQUESTS)
              Log.d("SCOPE", "Service discovery failure code "  + code);
          }
      });
  }
  </code></pre>
  
  <p>The first time I run my service after rebooting the phone, service discovery is initiated just fine, but if I kill the service by stopping it from the app settings page, then open it again, it always fails with error code 3. If I reboot my phone and run the app again it works just fine. I am confused because I am explicitly calling discoverServices only when the service request has been successfully added.</p>
  
  <p>My hunch is that it may be due to some code that is unrelated to service discovery because the service discovery code seems extremely straightforward, but if you see anything wrong with what I've posted, let me know. I'm grasping at straws here.</p>
  
  <p>I'm running this on a Nexus 5 with Android 4.4.2.</p>