![](/img/trans.png)
[英]IntentService onCreate() called but onHandleIntent() not
[英]IntentService's onDestroy method getting called straight after onHandleIntent
我有一个IntentService
,用于通过我的应用程序中的AudioRecord
记录音频。 在onHandleIntent
方法中,我调用用于处理记录的单独类的.getInstance
,然后调用该类的几个方法。
但是,一旦intentService启动,就会调用其onDestroy
方法,并且记录会停止。 在onHandleIntent
实例化的类中,音频仍在录制中,直到调用onDestroy
为止。 因此,在录制完成之前,肯定不会调用onDestroy
。
如果有人可以提出建议为什么这样做,将不胜感激。
我的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");
}
我相信extAudioRecord.start();
是非阻塞的,这意味着它会立即退出onHandleIntent()
。 IntentService在调用onDestroy
之后不久终止。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.