Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/188.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在使用音乐服务时在后台停止音乐_Java_Android_Service_Intentservice - Fatal编程技术网

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;
}

希望有帮助。

您面临什么问题?