Get Object from memory using memory adresse
Posted
by
Hamza Karmouda
on Stack Overflow
See other posts from Stack Overflow
or by Hamza Karmouda
Published on 2012-06-12T16:09:22Z
Indexed on
2012/06/12
16:40 UTC
Read the original article
Hit count: 199
I want to know how to get an Object from memory, in my case a MediaRecorder. Here's my class:
Mymic class:
public class MyMic {
MediaRecorder recorder2;
File file;
private Context c;
public MyMic(Context context){
this.c=context;
}
private void stopRecord() throws IOException {
recorder2.stop();
recorder2.reset();
recorder2.release();
}
private void startRecord() {
recorder2= new MediaRecorder();
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();
}
}
}
my Receiver Class:
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();
}
}
So when I'm calling startRecord()
it create a new MediaRecorder
but when i instantiate my class a second time i can't retrieve my Object. Can i retrieve my MediaRecorder
with his addresse
© Stack Overflow or respective owner