Wednesday, February 13, 2013

Re: [android-developers] Re: Binding to Android service in an external jar doesn't seem to be working

The discussion that I started initially was to find out if a service can be defined in a jar file (not Android library) and if the jar file can be distributed for application developers and if they can bind or start that service ?  I was simply unable to do it.  Ofcourse, the service was declared in the application's manifest file.  Once I created a Android library and defined the service in the library, then it worked fine, but with this approach, source code of the library will have to distributed.  

RK

On Wednesday, February 13, 2013 4:26:51 PM UTC-8, Kristopher Micinski wrote:
If I'm not misreading this discussion, the problem is that every
service must explicitly be declared in a manifest file.  There is no
such thing as implicitly or programmatically creating a service.
(This has an unfortunate benefit for would be dynamic scripting
languages implemented ala JVM wrapper which might otherwise allow you
to have first class components..)

This is pretty typical: lots of jars for Android are distributed with
the caveat that you need to explicitly declare a certain Service in
your Android manifest.

And yes, library projects basically allow you to do this for the user
using your project, so that they don't have to (as) explicitly set up
your components.

Kris

On Wed, Feb 13, 2013 at 5:11 PM, RKSHR <rks...@gmail.com> wrote:
> 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-d...@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscribe@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+unsubscribe@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

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

No comments:

Post a Comment