Skip to content

creating new service does not start the service #270

Closed

Description

@aoncorici

Dear all,

I would like to create a new service that starts when PythonService starts.
What I did was to create an aidl, java class to implement the Service interface and extend the Stub in the same package as PythonService.

I modified the manifest xml template to expose the service in the same process as PythonService, but still the service is not started.

When using the same code in another pure Java application the service starts well, a client can bind to it.

Can you tell me what key steps am I missing.

Thanks in advance for your help.

Ancuta Corici

Activity

  1. aoncorici commented on Sep 20, 2014

    @aoncorici
    Author

    I tried also to retrieve a Binder to the PythonService and did not work...maybe it is a problem of naming in the manifest. Can you tell me what could be the problem.

  2. FeralBytes commented on Feb 14, 2015

    @FeralBytes
    Contributor

    Can you show the code that you used to do this in Java and the code that failed for you in Python? Also at this time I do not know if it is possible the android.Service class was written a long time ago and needs much improvement to make it more like a real service, but Pyjinus may enable such changes. Also what do you mean by different packages? Different Apps, I would think that is possible.

  3. aoncorici commented on Feb 14, 2015

    @aoncorici
    Author

    Thank you for the answer. Yes, I am using Pyjnius. In the end the incompatibility/problem was that I was trying to create an AIDL service from another package than org.renpy.android. I had a deeper look but I got stuck in the way PythonService is initialized. In order to reproduce the environmental setting it would have taken me at lot of time and was not sure it was going to work. In the end I did not change the manifest as I decided to use a service exposed to bind operation from the PythonService, which is not exposing such a service originally. It would have been nice to have something plug and play.

  4. FeralBytes commented on Feb 14, 2015

    @FeralBytes
    Contributor

    Hey that sounds cool, would you share your Pyjnius code to start the additional service?

  5. aoncorici commented on Feb 16, 2015

    @aoncorici
    Author

    I guess I can resume the tricky part as:
    27 public static IBinder serviceBinder=null;
    28
    29 @OverRide
    30 public IBinder onBind(Intent arg0) {
    31 Log.v("python service", "onBind returning serviceBinder");
    32 return serviceBinder;
    33 }
    34
    35 public static void setBinder(IBinder binder){
    36 serviceBinder = binder;
    37 }

    The trick is to set the binder in the PythonService from Java/Pyjnius and then implement your own Binder. The AIDL files were compiled nicely. There was another problem when the AIDL is complicated and contains classes that are not inside your project. For that I used in the build line the option --add-jar to include the library containing those compiled Java classes.

    If you are wondering whre is this used, I am working on the non-open source project OpenMTC:
    http://www.openmtc.org/
    Thanks to Python-for-Android we have now our platform running on Android for getting data from sensors, sending commands (from the local device or from a device management server) to them and manage the connectivity of the device (locally or from a LWM2M device management server).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions