2014-05-15 40 views
0

這裏是我的問題的想法有些代碼:stopService(意圖)不停止服務?

@Override 
public void onDestroy() { 
    Log.e("onDestroy------------->", "onDestroy called"); 
    Toast.makeText(this, " onDestroy Started", Toast.LENGTH_LONG).show(); 
    super.onDestroy(); 
} 

b2.setOnClickListener(新OnClickListener(){

 @Override 
     public void onClick(View v) { 

      //startServiceManually(); 
      stopService(i); 

     } 
    }); 

請幫助在此先感謝

+0

看到這個http://stackoverflow.com/questions/9665256/android-stopservice-in-another-activity – User11

回答

0
try { 
stopService(new Intent(YOUR ACTIVITY NAME.this, YOUR SERVICE NAME.class));          
} catch (Exception e) {           e.printStackTrace();    
} 
+0

不工作服務仍然有響應。 – sambal

0

試試這個...

Intent i = new Intent(this, THE_SERVICE_NAME.class); 
    stopService(i); 

如果不起作用請確保您的服務具有的onDestroy,如果你使用的通知中的onDestroy,把

stopForeground(true); 

或者只是複製這個...

@Override 
public void onDestroy(){ 
    super.onDestroy(); 
    stopForeground(true); 
}