一旦我点击后退按钮离开活动,我的代码就会强制关闭。这里是。我认为它的作用是相对不言自明的。当被调用时,它会显示一些文本和一个按钮,当点击该按钮时会开始播放录音。当有人点击后退按钮时,它应该回到上一个活动并停止录制。谢谢你帮助我!
public class ToBeOrNot extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_to_be_or_not);
}
MediaPlayer mediaPlayer;
public void react(View view) {
mediaPlayer = MediaPlayer.create(ToBeOrNot.this, R.raw.achord);
mediaPlayer.start();
}
protected void onStop(){
mediaPlayer.release();
mediaPlayer = null;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
//getMenuInflater().inflate(R.menu.activity_to_be_or_not, menu);
// Locate MenuItem with ShareActionProvider
return true;
}
}