0

I would to clarify some stuff about services, thread and asynctask.

If I would to manage a Bluetooth (BLE or not) in my app, is there some reason or a particular case where I need to use one of that classes?

Are there some restriction or a particular case where one of that classes is the best of?

Could anyone explain me the differences about priorities of that classes?

Thanks in Advance

grrigore
  • 1,050
  • 1
  • 21
  • 39
DoctorWho
  • 1,044
  • 11
  • 34

1 Answers1

1

Basics of these is to avoid blockade of Main Thread. I will explain briefly in one line for each and that will be enough for you I hope.

AsyncTask:

Normally used for asynchronous work which probably takes 5 to 10 seconds

Services:

Normally used to do asynchronous work for longer period of time e.g, downloading or uploading heavy data in background without interrupting user's interaction with application

Thread:

Thread is basic class and normally used if you want fully control on work flow of tasks. Services and AsyncTask classes uses Thread behind the scenes.

Hence, you should know what kind of data communication is required with Bluetooth.

Zaid Mirza
  • 3,540
  • 2
  • 24
  • 40
  • Very clear, Thanks. So, I hava another little (I believe) question: which is the differencies between asynchronous and syncronous work flow? or in anothers words, are there only asynchronous stuff in android? Or are they referred only for background works? – DoctorWho Sep 16 '18 at 13:49
  • 1
    asynchronous and synchronous is general concept in programming. Check this link for details about it. https://stackoverflow.com/questions/748175/asynchronous-vs-synchronous-execution-what-does-it-really-mean – Zaid Mirza Sep 16 '18 at 13:52