Thursday, February 12, 2009

Update to services in Android...

...it turns out that what you really should do, if your code is in separate projects, is to declare a global (I presume) service moniker like this (in your service's manifest):

<action android:name="com.android.TestService.TEST_SERVICE" />

Then, change the method by which you call startService to call like this:

startService( new Intent( "com.android.TestService.TEST_SERVICE" ) );

NOTE: The argument is a string, which is the key. (Don't forget to change your invocation to stopService if you call that as well.)

Google might want to think about software less for tinkerers and more for real software engineers who will need to organize their code and look for opportunities to re-use, especially regarding services, and mention in their documentation that they recommend you add this naming schema to your service manifests for good reason. I'm just glad I noticed it in the remote services sample code.

No comments:

Post a Comment