[英]IntentService's onDestroy method getting called straight after onHandleIntent
I have an IntentService
that I am using to record audio via AudioRecord
in my app. 我有一个IntentService
,用于通过我的应用程序中的AudioRecord
记录音频。 In the onHandleIntent
method, I call .getInstance
of a seperate class that I used for handling the recording, and then call a couple of methods of that class. 在onHandleIntent
方法中,我调用用于处理记录的单独类的.getInstance
,然后调用该类的几个方法。
However as soon as the intentService starts, its onDestroy
method gets called, and the recording stops. 但是,一旦intentService启动,就会调用其onDestroy
方法,并且记录会停止。 In the class that gets instantiated in the onHandleIntent
, the audio is still recording, until the onDestroy
gets called. 在onHandleIntent
实例化的类中,音频仍在录制中,直到调用onDestroy
为止。 So surely onDestroy
shouldn't get called until the recording is finished. 因此,在录制完成之前,肯定不会调用onDestroy
。
If someone could offer a suggestion as to why it is doing this, it would be much appreciated. 如果有人可以提出建议为什么这样做,将不胜感激。
The code for my IntentService is below: 我的IntentService的代码如下:
public class RecordService extends IntentService {
public File directory;
AudioRecord audioRecord;
int sampleRate = 44100;
int channelConfiguration = AudioFormat.CHANNEL_IN_MONO;
int audioEncoding = AudioFormat.ENCODING_PCM_16BIT;
File file;
short channels = 1;
int bitsPerSample = 16;
public RecordService() {
super("Record");
}
ExtAudioRecorder extAudioRecord;
@Override
protected void onHandleIntent(Intent intent) {
Log.v("Record", "Record called");
extAudioRecord = ExtAudioRecorder.getInstanse(false);
extAudioRecord.reset();
extAudioRecord.setOutputFile(getOutputFile("RecV2").toString());
extAudioRecord.prepare();
extAudioRecord.start();
//record();
}
public void onDestroy(){
extAudioRecord.stop();
//audioRecord.stop();
Log.v("Record", "onDestroy called, Record stopped");
}
I believe the extAudioRecord.start();
我相信extAudioRecord.start();
is non-blocking meaning it returns immediately exiting onHandleIntent()
. 是非阻塞的,这意味着它会立即退出onHandleIntent()
。 The IntentService is terminated shortly after calling onDestroy
. IntentService在调用onDestroy
之后不久终止。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.