title: VideoCastManager crashes Android app on Phone boot
body: <p>I created simple app, which uses <a href="https://github.com/googlecast/CastCompanionLibrary-android" rel="nofollow">CastCompanionLibrary</a> to stream video files to Google ChromeCast device. Everything seems to work fine, except I found that app crashes when booting phone without internet connection. I tried catch error on ADB monitor. </p>
  
  <pre><code>java.lang.RuntimeException: Unable to start receiver com.google.android.libraries.cast.companionlibrary.remotecontrol.VideoIntentReceiver: java.lang.IllegalStateException: No VideoCastManager instance was found, did you forget to initialize it?
  </code></pre>
  
  <p>What makes me wonder is, why my app is starting at phone boot at all? It was supposed to start only when user starts it. </p>
  
  <p>However after some digging I believe it's something to do with CastCompanionLibrary mentioned before, which registers some service and receivers using manifest file. </p>
  
  <p><strong>Manifest.xml part</strong></p>
  
  <pre><code>&lt;activity
          android:name="com.google.android.libraries.cast.companionlibrary.cast.player.VideoCastControllerActivity"
          android:screenOrientation="portrait"
          android:label="@string/app_name"
          android:launchMode="singleTask"
          android:parentActivityName="lv.test.myapp.MainActivity"
          android:theme="@style/Theme.AppCompat.Light.NoActionBar"&gt;
          &lt;meta-data
              android:name="android.support.PARENT_ACTIVITY"
              android:value="lv.test.myapp.MainActivity" /&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
      &lt;receiver android:name="com.google.android.libraries.cast.companionlibrary.remotecontrol.VideoIntentReceiver" &gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.media.AUDIO_BECOMING_NOISY" /&gt;
              &lt;action android:name="android.intent.action.MEDIA_BUTTON" /&gt;
              &lt;action android:name="com.google.android.libraries.cast.companionlibrary.action.toggleplayback" /&gt;
              &lt;action android:name="com.google.android.libraries.cast.companionlibrary.action.stop" /&gt;
          &lt;/intent-filter&gt;
      &lt;/receiver&gt;
      &lt;service
          android:name="com.google.android.libraries.cast.companionlibrary.notification.VideoCastNotificationService"
          android:exported="false" &gt;
          &lt;intent-filter&gt;
              &lt;action
                  android:name="com.google.android.libraries.cast.companionlibrary.action.notificationvisibility" /&gt;
          &lt;/intent-filter&gt;
      &lt;/service&gt;
      &lt;service
          android:name="com.google.android.libraries.cast.companionlibrary.cast.reconnection.ReconnectionService"/&gt;
      &lt;receiver android:name="com.google.android.gms.analytics.AnalyticsReceiver"
          android:enabled="true"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="com.google.android.gms.analytics.ANALYTICS_DISPATCH" /&gt;
          &lt;/intent-filter&gt;
      &lt;/receiver&gt;
  </code></pre>
  
  <p><strong>Mainactivity part</strong></p>
  
  <pre><code>public VideoCastManager mCastManager;    
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
  //id changed for public use
  
      CastConfiguration options = new CastConfiguration.Builder("000000") 
  .enableAutoReconnect()
  .enableLockScreen()
  .enableWifiReconnection()
  .enableNotification()
  .build();
  
      if(mCastManager == null) {
          VideoCastManager.initialize(this, options);
      }
      mCastManager = VideoCastManager.getInstance();
  //some other not related code here
  }
  </code></pre>
  
  <p><strong>Full error I found</strong></p>
  
  <pre><code>04-07 22:12:32.185 5022-5022/? E/AndroidRuntime: FATAL EXCEPTION: main
                                               Process: lv.test.myapp, PID: 5022
                                               java.lang.RuntimeException: Unable to start receiver com.google.android.libraries.cast.companionlibrary.remotecontrol.VideoIntentReceiver: java.lang.IllegalStateException: No VideoCastManager instance was found, did you forget to initialize it?
                                                   at android.app.ActivityThread.handleReceiver(ActivityThread.java:3114)
                                                   at android.app.ActivityThread.access$1800(ActivityThread.java:181)
                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1551)
                                                   at android.os.Handler.dispatchMessage(Handler.java:102)
                                                   at android.os.Looper.loop(Looper.java:145)
                                                   at android.app.ActivityThread.main(ActivityThread.java:6117)
                                                   at java.lang.reflect.Method.invoke(Native Method)
                                                   at java.lang.reflect.Method.invoke(Method.java:372)
                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
                                                Caused by: java.lang.IllegalStateException: No VideoCastManager instance was found, did you forget to initialize it?
                                                   at com.google.android.libraries.cast.companionlibrary.cast.VideoCastManager.getInstance(VideoCastManager.java:259)
                                                   at com.google.android.libraries.cast.companionlibrary.remotecontrol.VideoIntentReceiver.onReceive(VideoIntentReceiver.java:49)
                                                   at android.app.ActivityThread.handleReceiver(ActivityThread.java:3107)
                                                   at android.app.ActivityThread.access$1800(ActivityThread.java:181) 
                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1551) 
                                                   at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                   at android.os.Looper.loop(Looper.java:145) 
                                                   at android.app.ActivityThread.main(ActivityThread.java:6117) 
                                                   at java.lang.reflect.Method.invoke(Native Method) 
                                                   at java.lang.reflect.Method.invoke(Method.java:372) 
                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399) 
                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194) 
  04-07 22:12:32.200 2888-3384/? V/ApplicationPolicy: isApplicationStateBlocked userId 0 pkgname lv.test.myapp
  </code></pre>