I\'m recording the sound from device with AudioRecord and write it to .wav file and I need it to keep recording and writing in file even wh
You should start recording/initialize AudioRecord
in independent thread, and start this thread you need from foreground Service
. Also right before start of recording change thread priority like in example below:
android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_AUDIO);
AudioRecord record = new AudioRecord(MediaRecorder.AudioSource.MIC,
sampleRate,
AudioFormat.CHANNEL_IN_MONO,
AudioFormat.ENCODING_PCM_16BIT,
bufferSize);
record.startRecording();