title: BroadcastReceiver dies with app
body: <p>If i let the phone sit for a long time like 15 minutes i lose my receiver but i thought it was to persist like a service after being killed for memory.</p>
  
  <p>Manifest:</p>
  
  <pre><code>&lt;receiver
      android:name=".WearableReceiver"
      android:enabled="false"&gt;
      &lt;intent-filter&gt;
          &lt;action android:name="com.example.johnbravado.MESSAGE_PROCESSED"/&gt;
      &lt;/intent-filter&gt;
  &lt;/receiver&gt;
  </code></pre>
  
  <p>In Activity to start receiver</p>
  
  <pre><code>ComponentName component = new ComponentName(CounterActivity.this, WearableReceiver.class);
  getPackageManager()
      .setComponentEnabledSetting(component,
          PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
          PackageManager.DONT_KILL_APP);
  </code></pre>
  
  <p>The receiver</p>
  
  <pre><code>@Override
  public void onReceive(Context context, Intent intent) {
      // TODO: This method is called when the BroadcastReceiver is receiving
      // an Intent broadcast.
      //MyConstants.getInstance().showToast("Message Rcvd");
      PowerManager powerManager = (PowerManager) context.getSystemService(POWER_SERVICE);
      PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
              "com.example.johnbravado");
      wakeLock.acquire();
      // Do Work
      MyConstants.getInstance().msgReqAction(intent.getIntExtra(MyConstants.BROADCAST_DATA_REQ, 0));
  
      wakeLock.release();
  }
  </code></pre>
  
  <p>The broadcast sender</p>
  
  <pre><code>String BROADCAST_ACTION_RESP = "com.example.johnbravado.MESSAGE_PROCESSED"
  @Override
  public void onMessageReceived(final MessageEvent messageEvent) {
      nodeId = messageEvent.getSourceNodeId();
      String incomingPath = messageEvent.getPath();
      int incomingReq = Integer.parseInt(new String(messageEvent.getData()));
  
      if(incomingPath.equalsIgnoreCase(MyConstants.MSG_COUNTER_REQ_PATH)) {
          Intent broadcastIntent = new Intent();
          broadcastIntent.setAction(BROADCAST_ACTION_RESP);
          broadcastIntent.putExtra(MyConstants.BROADCAST_DATA_REQ, incomingReq);
          sendBroadcast(broadcastIntent);
  
      }else if(incomingPath.equalsIgnoreCase(MyConstants.MSG_DEFAULT_PATH)){
  
      }
  }
  </code></pre>
  
  <p>only way I get this to persist for long periods of time is to invoke a service</p>
  
  <pre><code>wearableReceiverIntent = new Intent(this, WearableReceiverService.class);
  if(!WearableReceiverService.isRunning())
      startService(wearableReceiverIntent);
  </code></pre>
  
  <p>the service</p>
  
  <pre><code>@Override
  public int onStartCommand(Intent intent, int flags, int startId) {
      // Let it continue running until it is stopped.
      IntentFilter filter = new IntentFilter(MyConstants.BROADCAST_ACTION_RESP);
      filter.addCategory(Intent.CATEGORY_DEFAULT);
      receiver = new WearableReceiver();
      registerReceiver(receiver, filter);
  
  Notification notification = new NotificationCompat.Builder(this)
          .setSmallIcon(R.drawable.ic_notif_bible)
          .setContentText("Preaching").build();
  startForeground(MyConstants.NOTIF_COUNTING_SERVICE, notification);
  
      isRunning = true;
      return START_STICKY;
  }
  </code></pre>
  
  <p>If I run the service it persists for long periods of time but it drains the battery unnecessarily considering I interact only once every 10 minutes. I was under impression Broadcast receiver would work like service except for short bursts of work. invoke the service if you need to do long actions.</p>