I'm posting this to share the lessons I learned while working with
IntentService.

IntentService has a single constructor that takes a string argument
"name". The documentation has no description of what name is used for.
In looking at the sources, I found that its only use is in naming the
worker thread for the IntentService. This thread is named IntentService
[name].

I initially implemented the constructor of the derived class to also
take a String argument and passed it along to the derived class. This
is wrong. This will cause the startService() call to generated a
java.lang.InstantiationException in the application containing the
service i.e. you don't get the exception in the application calling
startService(). A clue to the actual problem is a little further up in
the logs:"newInstance failed: no <init>()"

The derived class must have a Default constructor and that constructor
must call super() passing a string for the name component of the
worker thread name.

public class MyIntentService extends IntentService
{
    public MyIntentService() {
        super("MyIntentService");
    }

    @Override
    protected void onHandleIntent(Intent intent)
    {
        // Handle events on worker thread here
    }
}



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to