Java 如何在使用音乐服务时在后台停止音乐
当我播放应用程序,然后关闭后,有时应用程序音乐会在后台再次启动 任何帮助都将不胜感激 谢谢 我有一个包含代码的活动类 @凌驾Java 如何在使用音乐服务时在后台停止音乐,java,android,service,intentservice,Java,Android,Service,Intentservice,当我播放应用程序,然后关闭后,有时应用程序音乐会在后台再次启动 任何帮助都将不胜感激 谢谢 我有一个包含代码的活动类 @凌驾 public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.mygame); final Handler mHandler = new Handler(); Intent svc=
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mygame);
final Handler mHandler = new Handler();
Intent svc=new Intent(this, MusicService.class);
startService(svc);
// Create runnable for posting
final Runnable mUpdateResults = new Runnable() {
public void run() {
AnimateandSlideShow();
}
};
int delay = 500; // delay for 1 sec.
int period = 6000; // repeat every 4 sec.
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
public void run() {
mHandler.post(mUpdateResults);}
}, delay, period);}
public void onClick(View v) {
finish();
android.os.Process.killProcess(android.os.Process.myPid());
Intent srv=new Intent(SliderActivity.this, MusicService.class);
stopService(srv); }
尝试删除activity类中onStop方法中处理程序的回调:
@Override
protected void onStop() {
super.onStop();
mHandler.removeCallbacksAndMessages(null);
timer = null;
mHandler= null;
}
希望有帮助。您面临什么问题?