title: How to fix the Android error "Background execution not allowed: receiving Intent {...}"
body: <p>So I'm programming an Android app that uses Bluetooth discovery of devices. Here is the code I use to start discovery.</p>
  
  <pre><code>try {
      myBluetoothAdapter.startDiscovery();
      Log.d("Bluetooth Started successfully","yes");
  } catch (Error e) {
      Log.d("FAILED","Ya failed mate");
      e.printStackTrace();
  }
  </code></pre>
  
  <p>I then register a BroadcastReceiver to watch for when devices are found. Here is my code for that</p>
  
  <pre><code>IntentFilter intentFilter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
  final ArrayList&lt;String&gt; stringArrayList = new ArrayList&lt;&gt;();
  final ArrayAdapter&lt;String&gt; arrayAdapter = new ArrayAdapter&lt;&gt;(getApplicationContext(),android.R.layout.simple_list_item_1,stringArrayList);
  final ListView listView = findViewById(R.id.listView);
  listView.setAdapter(arrayAdapter);
  BroadcastReceiver myReceiver = new BroadcastReceiver() {
      @Override
      public void onReceive(Context context, Intent intent) {
      String action = intent.getAction();
      Log.d("ACTION RECEIVED","Action was received");
      Log.d("Device Name", String.valueOf(intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE)));
      if (BluetoothDevice.ACTION_FOUND.equals(action)) {
          BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
          stringArrayList.add(device.getName());
          arrayAdapter.notifyDataSetChanged();
          listView.invalidateViews();
      }
      }
  };
  registerReceiver(myReceiver,intentFilter);
  </code></pre>
  
  <p>The listView, arrayAdapter, and stringArrayList are just things I'm "logging" to.</p>
  
  <p>The problem is that whenever I run that code I get this error and my code doesn't function. I'm assuming that the reason it doesn't function is because of this error.</p>
  
  <pre><code>W/BroadcastQueue: Background execution not allowed: receiving Intent { act=android.bluetooth.adapter.action.DISCOVERY_STARTED flg=0x10 } to com.verizon.messaging.vzmsgs/com.verizon.vzmsgs.receiver.DevicePairingListener
  </code></pre>
  
  <p>Can someone tell me what this error means as well as how to fix it?</p>
  
  <p>I also find other questions on Stack Overflow with errors that look very similar; like, instead of Bluetooth, it will be in the context of BOOT_COMPLETED, ACTION_POWER_DISCONECTED, or BATTERY_LOW. How are those similar to this.</p>