user1527152
user1527152

Reputation: 956

IntentService stop app on startService()

My app crashes when I call startService(). The problem is that I don't get an error in the console and thus I don't know how to troubleshoot this crash.

I am looking for way to troubleshoot my problem if anybody has some leads. I was thinking maybe I can't start a service from the onCreate method of the main activity for some reason.

I start the service from the onCreate() method of the main activity:

serviceIntent = new Intent(this, myIntentService.class);
        startService(serviceIntent);

The following is the only code I have in myIntentService class:

 public myIntentService(String name) {
        super(name);
    }

    @Override
    protected void onHandleIntent(@Nullable Intent intent) {

        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            // Restore interrupt status.
            Thread.currentThread().interrupt();
        }

        Log.v("Info", "Service " + this.getClass().getSimpleName() + " received a request");
        //executeRequest();
    }

If I comment the startService() line the app open without crashing.

I used this question to check is my service is running:

Log.v("Info", "Is Service "+ WhichAuthCurrentService.class.getSimpleName() + " running? response: " + isMyServiceRunning(myIntentService.class));

Which write in the console:

Is Service WhichAuthCurrentService running? response: true

Notes I do not implement methods, such as onCreate(), onStartCommand(), nor onDestroy() and I added my service to AndroidManifest.xml.
All the related question I found were solved by properly overwriting these method or adding the service to the Android Manifest.

Upvotes: 0

Views: 181

Answers (2)

Amirhosein
Amirhosein

Reputation: 4446

Change:

 public myIntentService(String name) {
        super(name);
    }

to:

 public myIntentService() {
        super("myIntentService");
    }

Upvotes: 1

Ahmed Hegazy
Ahmed Hegazy

Reputation: 12605

This happens because you don't have a default constructor for your Service, just remove the constructor or add a default one(no parameters) and it'll magically work!

Upvotes: 1

Related Questions