I spent some more time and this is what I found so far.

- An app cannot bind to a service or instantiate a service if the service 
is declared in a jar file (that is not a Android library).  Note that I'm 
just building a jar file using javac compiler and jar utility, without the 
need for AndroidManifest xml file. I tried creating a TestService class 
that extends Service class and built that into a jar.  In a test app, I 
imported the jar file and put a break point in onStart() and onCreate() 
methods of TestService class.  In the app I tried calling both bindService 
and startService, both of them return a false or a null value and the 
debugger never breaks in onStart() or onCreate().  Both these methods had 
one line implementations with a just a call to their super class like 
super.onStart().

- In the next step I moved the TestService outside of the jar into an 
Android library (in Eclipse enable checkbox "Is Library" or 
project.properties should contain android.Library=true ).  I built the 
library and included it into the test app. Now i can instantiate the 
service using bindService API from the app, the debugger breaks in 
onStart() and onCreate()  methods of TestService class.


On Monday, February 11, 2013 4:30:56 PM UTC-8, Lew wrote:
>
> RKSHR wrote:
>>
>> No the JAR is not set up as a Library project, as all I have is, compile 
>> the classes using javac and then bundle them into a jar using jar builder.
>
>
> You should probably build it as a library project, since it does have 
> something specific to Android in it. 
>
> I'm not expert in library projects, but as I understand they're the way to 
> package Android stuff for other Android stuff.
>
>
> By "nothing specific to android [sic]", I meant the classes used within 
> the service, other than the obvious service class.  I did not have this 
> service class before and there is a singleton factory class that the app 
> was using to instantiate.  Now I have moved the factory instantiation into 
> the service class. I want the app to just bind to the service, so the 
> factory instantiation happens in the background within the service.
>
>
> There's a world of difference between "nothing" and "nothing other than... 
> ".
>
> And that difference might be the difference that makes the difference. You 
> might want to investigate.
>  
>
>> Lew wrote:
>>>
>>> RKSHR wrote:
>>>
>>>> I did make sure that there were no R.xx classes in the service, infact 
>>>> I dont need any resources in the service.  I did double check again and 
>>>> nothing was present, although an import definition to resources class was 
>>>> left there.  I wasn't sure if it would make a difference, but I removed 
>>>> that definition anyway and recompiled the jar without any different 
>>>> result. 
>>>>  The application loading the jar, still cannot bind to the service. The 
>>>> service is a very simple class that just instantiates a set of regular 
>>>> java 
>>>> classes (nothing specific to Android).  I'm not even able to debug into 
>>>> the 
>>>> service,  I have a break point at onStart() and onCreate() methods and it 
>>>> never falls there. I will continue looking. .thanks.
>>>
>>>
>>> "nothing specific to Android" is obviously false since there's a service 
>>> class in there.
>>>
>>> Is the JAR source set up as an Android library project?
>>>
>>>  
>

-- 
-- 
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
--- 
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 android-developers+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to