我正在发出警报,所以当我关闭项目时如何停止声音????因为我关闭它时声音仍在播放,如何停止它?我已经放了这个但是没有用:
@Override
protected void onStop(){
super.onStop();
//your code for stopping the sound
}
这是代码
public class MainActivity extends Activity {
ImageView img;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
MediaPlayer media = MediaPlayer.create(getBaseContext(), R.raw.alarm);
media.start();
img = (ImageView) findViewById(R.id.img);
img.setImageResource(R.drawable.image1);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}