title: BroadcastReceiver works for a while, then stops
body: <p>I'm developing an android app that responds to incoming calls. I've set up a broadcast receiver, set the permission and intent filter in the manifest file, and a lot of the time, it works. I can kill all apps, reboot the phone and it still works.. </p>
  
  <p>However, sometimes it doesn't react, and after this happens once, it doesn't respond after a reboot either. </p>
  
  <p>I've been struggling with this for about a month and it's driving me bananas. I really need my app to respond every time an incoming call is received. </p>
  
  <p>I've tried trimming out all code, and just displaying a Toast message when a call is received or ends. Even when the app does nothing else but this, the behaviour is still the same.</p>
  
  <p>I can't replicate this on an emulator, I'm using my <strong>HUAWEI ASCEND Y550</strong> to device test. </p>
  
  <p>Any help is hugely appreciated,</p>
  
  <p>David</p>
  
  <p><b>Manifest:</b></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.test.app.receivertest" &gt;
  
    &lt;uses-permission android:name="android.permission.READ_PHONE_STATE" /&gt;
  
    &lt;application
      android:allowBackup="true"
      android:icon="@drawable/ic_launcher"
      android:label="@string/app_name"
      android:theme="@style/AppTheme" &gt;
      &lt;activity
          android:name=".MainActivity"
          android:label="@string/app_name" &gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
      &lt;receiver android:name=".CallReceiver" android:enabled="true"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.PHONE_STATE" /&gt;
          &lt;/intent-filter&gt;
      &lt;/receiver&gt;
    &lt;/application&gt;
  &lt;/manifest&gt;
  </code></pre>
  
  <p><b>My Receiver:</b></p>
  
  <pre><code>public class CallReceiver extends BroadcastReceiver {
  
    @Override
    public void onReceive(Context context, Intent intent) {
      try {
          if (context == null &amp;&amp; intent == null)
              return;
  
          String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
  
          String action = intent.getAction();
          Toast.makeText(context, action + " " + state, Toast.LENGTH_SHORT).show();
      } catch (Exception ex) {
          try {
              Toast.makeText(context, "Error", Toast.LENGTH_SHORT).show();
          }
          catch (Exception e)
          {
          }
      }
    }
  }
  </code></pre>