private static class MyHandle extends Handler {
WeakReference<Activity> weakReference;
public MyHandle(Activity activity) {
weakReference = new WeakReference<Activity>(activity);
}
@Override
public void handleMessage(Message msg) {
Activity activity = weakReference.get();
if (activity != null && activity instanceof TestMainActivity) {
switch (msg.what) {
case START_RECORD:
isListener = true;
fileRecod = FileUtil.createFile("test.amr");
if (fileRecod != null) {
startRecord();
}
break;
default:
break;
}
super.handleMessage(msg);
}
}
}
@Override
protected void onDestroy() {
super.onDestroy();
if (myHandle != null) {
myHandle.removeCallbacksAndMessages(null);
}
}
Message msg = myHandle.obtainMessage();
msg.what = START_RECORD;
myHandle.sendMessage(msg);
网友评论