title: Android App Crashes After GCMIntentServce onRegistered Success
body: <p>I am experiencing a situation where a fresh install of my Android App will crash after it reaches the <code>onRegistered</code> function in my <code>GCMIntentService</code> file. The GCM registration is successful and I can retrieve the GCM Registration ID the next time I open the app, but I don't want it crashing the first time a user opens it. </p>
  
  <p>I use this to call for registration:</p>
  
  <pre><code>GCMRegistrar.checkDevice(this);
  GCMRegistrar.checkManifest(this);
  String regId = GCMRegistrar.getRegistrationId(this);
  if (regId.equals("")) {
       GCMRegistrar.register(this, getResources().getString(R.string.gcmToken));
  }
  </code></pre>
  
  <p>This is my <code>GCMIntentService</code> file</p>
  
  <pre><code>public class GCMIntentService extends GCMBaseIntentService {
  
      private static final String LOG_TAG = "GCM";
  
      public GCMIntentService() {
          super( "###############" ); // use my GCM ID
          // TODO Auto-generated constructor stub
          Log.i( LOG_TAG, "GCMIntentService constructor called" );
      }
  
      @Override
      protected void onError( Context arg0, String errorId ) {
          // TODO Auto-generated method stub
          Log.i( LOG_TAG, "GCMIntentService onError called: " + errorId );
      }
  
      @Override
      protected void onMessage( Context arg0, Intent intent ) {
          // TODO Auto-generated method stub
          Log.i( LOG_TAG, "GCMIntentService onMessage called" );
          Log.i( LOG_TAG, "Message is: " + intent.getStringExtra( "message" ) );
      }
  
      @Override
      protected void onRegistered( Context arg0, String registrationId ) {
          // TODO Auto-generated method stub
          Log.i( LOG_TAG, "GCMIntentService onRegistered called" );
          Log.i( LOG_TAG, "Registration id is: " + registrationId );
  
          // ! ! ! CRASHES HERE ! ! !
  
      }
  
      @Override
      protected void onUnregistered( Context arg0, String registrationId ) {
          // TODO Auto-generated method stub
          Log.i( LOG_TAG, "GCMIntentService onUnregistered called" );
          Log.i( LOG_TAG, "Registration id is: " + registrationId );
      }
  }
  </code></pre>
  
  <p>Here's the crash portion of the LogCat</p>
  
  <pre><code>V/GCMBaseIntentService(9604): Releasing wakelock
  W/dalvikvm(9604): threadid=10: thread exiting with uncaught exception (group=0x40020950)
  E/AndroidRuntime(9604): FATAL EXCEPTION: IntentService[GCMIntentService-##########-1]
  E/AndroidRuntime(9604): java.lang.ClassCastException: android.app.Application
  E/AndroidRuntime(9604): at com.myfile.app.GCMIntentService.onRegistered(GCMIntentService.java:85)
  E/AndroidRuntime(9604): at com.google.android.gcm.GCMBaseIntentService.handleRegistration(GCMBaseIntentService.java:296)
  E/AndroidRuntime(9604): at com.google.android.gcm.GCMBaseIntentService.onHandleIntent(GCMBaseIntentService.java:197)
  E/AndroidRuntime(9604): at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:59)
  E/AndroidRuntime(9604): at android.os.Handler.dispatchMessage(Handler.java:99)
  E/AndroidRuntime(9604): at android.os.Looper.loop(Looper.java:123)
  E/AndroidRuntime(9604): at android.os.HandlerThread.run(HandlerThread.java:60)
  D/dalvikvm(9604): GC_FOR_MALLOC freed 3478 objects / 299784 bytes in 815ms
  </code></pre>
  
  <p>Here is the Manifest file</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.myfile.app"
      android:versionCode="1"
      android:versionName="1.0" &gt;
  
  
      &lt;!--  B1 - BSG DEV --&gt;
  
      &lt;uses-sdk
          android:minSdkVersion="8"
          android:targetSdkVersion="15" /&gt;
  
      &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
      &lt;uses-permission android:name="android.permission.READ_PHONE_STATE"/&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /&gt;
      &lt;uses-permission android:name="android.permission.VIBRATE"/&gt;
  
      &lt;!--  Google Cloud Messaging --&gt;
      &lt;permission android:name="com.myfile.app.permission.C2D_MESSAGE" android:protectionLevel="signature" /&gt;
      &lt;uses-permission android:name="com.myfile.app.permission.C2D_MESSAGE" /&gt; 
      &lt;uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /&gt;
      &lt;uses-permission android:name="android.permission.GET_ACCOUNTS" /&gt;
      &lt;uses-permission android:name="android.permission.WAKE_LOCK" /&gt;
      &lt;!--  Google Cloud Messaging --&gt;
  
      &lt;application
          android:allowBackup="true"
          android:icon="@drawable/icon1"
          android:label="@string/app_name" &gt;
  
  
          &lt;activity
              android:name="com.myfile.app.MainActivity"
              android:label="@string/app_name" 
              android:screenOrientation="portrait"
              android:theme="@android:style/Theme.NoTitleBar.Fullscreen"&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;activity android:name="com.myfile.app.myclass" android:screenOrientation="portrait"/&gt;  
  
  
              &lt;!--  Google Cloud Messaging --&gt;
          &lt;receiver android:name="com.google.android.gcm.GCMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND" &gt;
            &lt;intent-filter&gt;
              &lt;action android:name="com.google.android.c2dm.intent.RECEIVE" /&gt;
              &lt;action android:name="com.google.android.c2dm.intent.REGISTRATION" /&gt;
              &lt;category android:name="com.myfile.app" /&gt;
            &lt;/intent-filter&gt;
          &lt;/receiver&gt;
          &lt;service android:name=".GCMIntentService" /&gt;
          &lt;!--  Google Cloud Messaging --&gt;
  
          &lt;/application&gt;
  
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>Any ideas about why this is happening would be greatly appreciated. </p>