android – How could Intent be null in onHandleIntent()?-ThrowExceptions

Exception or error:

My android app crashes and this is the logcat :-

    at android.os.Handler.dispatchMessage(
    at android.os.Looper.loop(

I looked into android gcm r3 source and I found that
the argument intent is null in onHandleIntent().

Is this even possible? How to fix it?

(I know null intent could be seen with Service.onStartCopmmand returning START_STICKY
but IntentService.onStartCommand doesn’t use START_STICKY.)

How to solve:

I think application crashes only in some devices during installation time. It’s because during installation GCM service also receives some Intent from other Google source and your broadcast receiver is not prepared to handle this type of Intent.

If you just want to receive GCM Intent which you want to pull from server through push notification, then just use this in your handle Intent call.

protected void onHandleIntent(Intent intent) {
Bundle extras = intent.getExtras();
        //String msg = intent.getStringExtra("message");
        String from=extras.getString("from");
        GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
        String messageType = gcm.getMessageType(intent);

        if (!extras.isEmpty()) {

            if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
                sendErrorNotification("Send error: " + extras.toString());
            } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
                sendErrorNotification("Deleted messages on server: " + extras.toString());
                // If it's a regular GCM message, do some work.
            } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
                // This loop represents the service doing some work.
                for (int i = 0; i < 5; i++) {
                    Log.i(TAG, "Working... " + (i + 1) + "/5 @ " + SystemClock.elapsedRealtime());
                    try {
                    } catch (InterruptedException e) {
                Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime());
                // Post notification of received message.
                // sendNotification("Received: " + extras.toString());
                /*********ERROR IN SOME DEVICES*****************/

                     //related to google ... DO NOT PERFORM ANY ACTION
                 else { 
                     String msg = intent.getStringExtra("message");
                    Log.i(TAG, "Received: " + extras.toString());


Happend to me once, I was passing wrong URI. Reference the documnetation for the intent u wanna pass.

Intent Documentation here.

Leave a Reply

Your email address will not be published. Required fields are marked *