0

I have read one post about Android services within threads but there is one thing that I did not understand. In the post the writer uses a custom service because it allows multitasking while IntentService does not.

https://guides.codepath.com/android/managing-threads-and-custom-services#custom-services

Until there everything is okay, but later the writer uses a HandlerThread which just allow one thread, as my point of view there is no difference between this and a normal IntentService.

https://guides.codepath.com/android/managing-threads-and-custom-services#threading-within-the-service

Am I right? or is there anything that I am missing? I am looking at this due I want to create a android service able to run different tasks at the same time, should I use ThreadPoolExecutor instead HandlerThread?

JMP
  • 75
  • 7
  • 1
    "...my point of view there is no difference between this and a normal IntentService." – They also mention that `IntentService` stops itself automatically when it runs out of tasks. The regular `Service` won't do that. It looks like they're just going for the simplest possible example, with that particular contrasting behavior. You can certainly use your own threading setup, in lieu of the demonstrated `HandlerThread`. – Mike M. Aug 15 '19 at 12:28
  • "IntentService stops itself automatically when it runs out of tasks" Right! I will try to go with `ThreadPoolExecutor ` but it is difficult to find any examples within a `Service`. I also saw `JobIntentService` but it does not allow multitasking. – JMP Aug 16 '19 at 07:21

1 Answers1

1

You should make yourself familiar with the changes to background execution introduced with Android 8.0 - you cannot freely execute background work in Services anymore the way you could when that tutorial was written.

https://developer.android.com/reference/android/support/v4/app/JobIntentService might be for you; if not, have a look at https://developer.android.com/topic/libraries/architecture/workmanager

Jule
  • 871
  • 5
  • 13
  • Thanks for your comment. I had a look at the `JobIntentService` but as I understood it works similar to `IntentService`, itself schedules all the jobs in one thread, I want multitasking so `JobIntentService` is not for me. I also looked the work manager, I want a service because I can call it from different apps, does `workmanager`allows that? Have not see in the doc page – JMP Aug 16 '19 at 07:03
  • You're right; `JobIntentService` really is the drop-in replacement for the old `IntentService`, preserving the serialized nature of handling the work tasks. Sorry about that. – Jule Aug 19 '19 at 09:02