Thank John,

It proved a time saver for me.


On Friday, 8 May 2009 23:37:46 UTC+5:30, John Seghers wrote:
>
> 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 unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/android-developers/57345e4b-3c44-4979-bfd9-a98a7d2ba788%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to