Reputation: 3962
I'm programming an Android
application (I'm using Android Studio
).
I start the recording with the following code (this is just a fragment):
public void start() {
int minBufferSize = AudioRecord.getMinBufferSize(SAMPLE_RATE, CHANNELS, AUDIO_ENCODING);
audioRecord = new AudioRecord(
MediaRecorder.AudioSource.MIC,
SAMPLE_RATE, CHANNELS, AUDIO_ENCODING,
minBufferSize
);
audioRecord.startRecording();
recordingThread = new Thread(new Runnable() {
public void run() {
readAudioData();
}
}, "AudioRecorder Thread");
recordingThread.start();
}
I want, when I press the home button, the application continues recording. Right now, when I press the home button, the recording stops.
Any idea on how to do this?
Upvotes: 1
Views: 141
Reputation: 1445
You can to create a service and you can start the service when you want to record audio it works even you press home button.
You can start service by
startService(new Intent(YourActivity,Service.class));
and can call that method onStartCommand()
and can stop service by this
stopService(new Intent(YourActivity,Service.class));
or by stopself();
Upvotes: 4