我想知道如何从内存中获取一个对象,在我的例子中是一个 MediaRecorder。这是我的课:
Mymic类:
public class MyMic {
MediaRecorder recorder2;
File file;
private Context c;
public MyMic(Context context){
this.c=context;
recorder2= new MediaRecorder();
}
private void stopRecord() throws IOException {
recorder2.stop();
recorder2.reset();
recorder2.release();
}
private void startRecord() {
recorder2.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder2.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder2.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder2.setOutputFile(file.getPath());
try {
recorder2.prepare();
recorder2.start();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
我的接收类:
public class MyReceiver extends BroadcastReceiver {
private Context c;
private MyMic myMic;
@Override
public void onReceive(Context context, Intent intent) {
this.c=context;
myMic = new MyMic(c);
if(my condition = true){
myMic.startRecord();
}else
myMic.stopRecord();
}
}
因此,当我调用startRecord()
它创建一个新的MediaRecorder
但当我第二次实例化我的类时,我无法检索我的对象。我可以MediaRecorder
用他的地址找回我的吗?