Wednesday, May 02, 2012

simple android service not starting

i'm new to android.
but it seems a nice platform so far.
been away from java for quite some time and find some syntax shortcuts are quite amazing but on the problem at hand;
i wanted to write a very simple test service and eventually settled for this scenario:
- start an activity
 - on button click the activity starts a service
- thats it!

and this gave me hours of grinding google and stackoverflow, because this very simple service never seemed to start

 one of the first issues was "newinstance failed no ()" that was quite easy to solve thanks to http://stackoverflow.com/questions/2120699/newinstance-failed-no-init. but then non of the debug loggers i put through out the code seemed to be fired i the service i had onCreate(), onStartCommand(), onStart() and none was ever triggered 
 i had big suspicions on the AndroidManifest.xml as it is still quite a blank area for me. startService() returned Null whatever i passed to it. 
my service was declared in the file that countained the activity so the name i tried to input as service android:name were like mainNamespace.Activityname.ServiceName, but this didn't work, nor did mainNamespace.ServiceName, not any of the other attempts 

 to save some hdd space on the blog host - i moved the code of the service outside the file containing the activity class, added new service name in the manifest xml and suddenly i started seeing the debug messages i waited to see for quite some time! 
 so what was i doing wrong? what should've been the name of the service in the manifest xml for the service class contained within the same file? or was it the naming in the Intent constructor? 
 just another android mystery 

 by the way, i had a glimpse of some iOs code, and must say i was startled to extent of appalled - is this C++, or some attribute based language, how do you program in this? maybe i've seen only some weird bits of code, i don't know - but i was hoping for some clean C++ code (Objective-C?) and didn't see any 

 bye..


oh yes - some helpful links, these were very helpful in grabbing some basic knowledge and sample code
- http://zaman91.wordpress.com/2010/04/22/android-how-to-start-a-service-in-application/
- http://marakana.com/forums/android/examples/60.html
- http://stackoverflow.com/questions/4480340/sample-alarmcontroller-application-service-registeration-in-androidmanifest