我想在onCreate()
和中运行相同的功能onResume()
。这些功能基本上在 10 秒内录制,然后停止并播放录制的声音。
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
new CountDownTimer(
10000, // 10 second countdown
9999) { // onTick time, not used
public void onTick(long millisUntilFinished) {
// Not used
}
public void onFinish() {
isRecording = false;
}
}.start();
Thread thread = new Thread(new Runnable() {
public void run() {
isRecording = true;
record(); // starts to record
}
});
thread.start(); // thread start
// thread to start
play();
}
如果我按下Home按钮,应用程序就会进入后台。现在,如果我再次点击应用程序的图标按钮,我想调用相同的录制和播放功能。
我可以做同样的事情onResume()
吗?基本上复制相同的东西。
public void onResume() {
super.onResume();
new CountDownTimer(
10000, // 10 second countdown
9999) { // onTick time, not used
public void onTick(long millisUntilFinished) {
// Not used
}
public void onFinish() {
isRecording = false;
}
}.start();
Thread thread = new Thread(new Runnable() {
public void run() {
isRecording = true;
record(); // starts to record
}
});
thread.start(); // thread start
play();
}