0

I converted all my IntentServices / Services in IntentJobServices / JobServices so my app is compatible with all security policy.

But I have a problem to Bind and Start my JobIntentService... I need to Start the IntentJob and then Bind to it, but when I do:

MyJobIntentService.enqueueWork(...)

Only my 'onBind' service get called and the 'onHandleWork' never get called.

I tried with the static method "enqueueWork" of my JobIntentService and of my Context, but none work right... Also I read and tested all topics here in Stackoverflow about this problem, but none gave me a good solution...

To solve my problem I did:

@Override @Nullable
public IBinder onBind(@NonNull Intent intent) {
    super.onBind(intent);
    new Thread(
        () -> onHandleWork(intent)
    ).start();
    initMessageManager();
    return this.mMessenger.getMsgReceiver().getBinder();
}

My JobIntentService and Binded Activity have both a Messenger Sender and Receiver to communicate synchronization status informations... So I must return the IBinder to my initiated Service's Messenger to the ServiceConnection in my Activity, so now I'm doing this to get the things work... But if my activity get killed the Binded Activity has a leaked ServiceConnection which throws an Exception and stop my Service. I am trying to solve that, and maybe I solved it, by unbinding my service when my activity gets destroyed..

Is that a good way to solve this problem or is there a better one?

Personally I don't like to start a thread in the onBind because my onHandleWork never got call on Android Versions >= 8.0, in Android Versions < 8.0 the JobIntentService works well because it calls the onHandleWork if I enqueue the JobService and it calls the onBind if I bind it. So is there a better way to solve this problem?

Thank you, Have a Nice Coding! :D Bye!

Edit: yeah sorry for my grammar errors, but I'm at work and I don't give a ... about that xD Anyway the "unbind" on the "onPause" or "onDestroy" lifecycle methods doesn't work... Because when I call the unbind the Service stop working and, if possible, I need that it still run.. Any Suggestion please?

Will they ever fix this problem with JobIntentService???

Z3R0
  • 1,011
  • 10
  • 19

1 Answers1

0

UP

Actually I'm solving the messaging through Activity - Service by using a Messenger instance without the IBinder returned from the OnBind method but by passing the Messenger's instance inside the intent which starts the service.

But I'll prefer to change it by using the onBind method as I was doing with classic "Service" classes. When this will be solved?

Z3R0
  • 1,011
  • 10
  • 19