2014-12-06 146 views
0

当我玩的应用,有时应用程序的音乐背景 再次启动再经过关闭任何帮助将不胜感激 感谢如何停止音乐背景,同时使用音乐服务

我有代码 的活动类@覆盖

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

回答

1

尝试在你的活动类中删除的方法的onStop您的处理程序的回调:

@Override 
protected void onStop() { 
    super.onStop(); 
    mHandler.removeCallbacksAndMessages(null); 
    timer = null; 
    mHandler= null; 
} 

希望它有帮助。

+0

你面临什么问题? – 2014-12-06 13:01:07