Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
This repository was archived by the owner on Feb 26, 2023. It is now read-only.

NPE in @EIntentService.onHandleIntent #1499

Description

@simonz

NullPointerException was often occurred in @EIntentService.onHandleIntent
This is the generated @EIntentService code,

    @Override
    public void onHandleIntent(Intent intent) {
        MyIntentService_.super.onHandleIntent(intent);
        String action = intent.getAction();
        if (ACTION_EXECUTE.equals(action)) {
            // ....
        }   

sometimes intent gets null, so intent.getAction() makes NPE.
And I could find the documentation from http://developer.android.com/reference/android/app/IntentService.html#onStartCommand(android.content.Intent,%20int,%20int)

The Intent supplied to startService(Intent), as given. This may be null if the service is being restarted after its process has gone away, and it had previously returned anything except START_STICKY_COMPATIBILITY.

I think it is safe to check whether intent is null.

Activity

  1. WonderCsabo commented on Jul 20, 2015

    @WonderCsabo
    Member
  2. simonz commented on Jul 22, 2015

    @simonz
    ContributorAuthor

    Yes, you're right. I was confused about the flags of Service.
    I'm using IntentService as NOT_STICKY mode, but I reported NPE from Crashlytics.
    the intent cannot be null, according to the document. Anyway I will reopen this issue after I get more information.
    Thank you

  3. chrulri commented on Aug 14, 2016

    @chrulri

    I don't have more information, except that - according to my Crashlytics monitoring - this is happening from time to time in my app too. I'm using version 4.0.0 of AndroidAnnotations and only start the one IntentService using the builder methods provided by AndroidAnnotations.
    Any ideas why the Intent could be occasionally null?

  4. Ron-lab commented on Jun 14, 2017

    @Ron-lab

    Same issue for me.
    Any Solutions?

  5. WonderCsabo commented on Jun 14, 2017

    @WonderCsabo
    Member

    @dodgex according to the JavaDoc, the intent parameter can be indeed null. So we have to add an additional check here.

  6. dodgex commented on Jun 14, 2017

    @dodgex
    Member

    PR is up. :)

  7. WonderCsabo commented on Jun 16, 2017

    @WonderCsabo
    Member

    Finally fixed. Thanks @dodgex.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions