0
I’m starting to develop an android app that will "listen" to the audio and will draw its waveform on the screen. But the first step I wanted to just "listen" to the audio and show on the screen the value read in real time. And to do that I’m using the Audio Record class:
AudioRecord audioRecord= new AudioRecord(MediaRecorder.AudioSource.MIC, TaxaAmostragem, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT, minBufferSize);
Only that means the doubt of which would be the best option to do this process in real time: Thread or Asynctask? Researching a little I saw that Asynctask is only recommended for applications that last a few seconds but consulting materials on the net about it I saw some works that use Asynctask to do this. There I am in doubt whether or not I can use Asynctastk, since it is easier to use.
EDIT Had already read this link and in it is said the following
This restriction only applies if Asynctask is executed through the execute() method. This method executes the Tasks sequentially, in a single thread, causing the next Task to start only after the completion of the previous one. The constraint can be avoided by using the executable methodOnExecutor(), passed to it an executor, usually Asynctask.THREAD_POOL_EXECUTOR, in order to use a thread pool to perform tasks in parallel.
- So, if I want to use Asynctask to perform ongoing tasks, which will be performed while the app is open, I can do this using the executableOnExecutor(Asynctask.THREAD_POOL_EXECUTOR) method instead of running() smoothly ?
- My app will need to make use of other threads to do other tasks, such as downloading images for example. I will use Asynctask but at the same time the audio processing Asynctask will be running because while the app is open it will be running. In case I could use more than one Asynctask if I use the executable methodOnExecutor(Asynctask.THREAD_POOL_EXECUTOR) ?
- In this specific case which would be the best option: Use Asynctask in parallel or use Threads?
Related: Thread or Asynctask? When and which one should I use?
– Homer Simpson
at this link : https://answall.com/questions/82399/quais-as-principais-differences-entre-handler-thread-e-asynctask
– Armando Marques Sobrinho
@Armandomarquessobrinho The pegunta has been edited. Thanks in advance for the help!
– L.J
@Henriquea question was edited.
– L.J
OK @Lucasjunior, entail, in the specific case of the sound I in your case would use the thread, even because, from what I could understand this will be a unique thread, ie soh to run the sound, and also, because an asynctask a thread, but the control of this thread is at her own discretion, while in a normal thread, the control is yours, this has a big difference for who programs, dai creates another post specifying the problem that will solve using threads and we try to see together a solution, I’ve got something like this here
– Armando Marques Sobrinho