我在停止播放音頻文件的服務時遇到很大問題。我想在播放其他文件之前停止當前的服務。Android:stopService()不會調用onDestroy()!
活動:
public void playTrack(View view){
Intent i=new Intent(this,playService.class);
i.setAction("com.c0dehunterstudios.relaxer.PLAY");
if(isPlaying){
stopService(i);
isPlaying=false;
Log.v("ACTIVITY", "Stopping..");
}
startService(i);
isPlaying=true;
}
服務:
public void OnDestroy(){
Log.v("SERVICE","Service killed");
player.stop();
super.onDestroy();
}
但可悲的是它不工作 - 事實上,它甚至不下來 「服務殺」 裏面的OnDestroy()。
我在做什麼錯?
謝謝你,你解決了我的 「問題」。 – 2012-01-31 20:38:51
此外,如果您使用的是Eclipse(因爲大多數人都在使用Android,我認爲),請嘗試養成使用「Source-> Override/Implement Methods」菜單命令的習慣 - 這將爲該函數創建一個存根準備好讓你填寫,並且你將無法在名字上輸入錯誤。 – 2012-01-31 20:43:55
謝謝,很好的建議! – 2012-01-31 20:53:42