2014-05-17 36 views
1

我的應用程序具有綁定到活動的遠程,前臺輔助服務。當我清除最近的任務(通過刷卡)服務銷燬。我怎樣才能防止殺人的服務。清除最近的任務時防止終止服務

<service android:enabled="true" 
       android:exported="false" 
       android:stopWithTask="false" 
       android:process=":xplay" 
       android:name="com.perm.x.Services.PlayingService"/> 

下面是我(在的onResume)結合

Intent serviceIntent = new Intent(this,PlayingService.class); 
     startService(serviceIntent); 
     bindService(serviceIntent, serviceConnection, Context.BIND_AUTO_CREATE); 

這裏是我我怎麼解除綁定服務(在的onPause)

unbindService(serviceConnection); 
+0

應用程序後您的設備是否有哪個版本的Android?該服務是否最終會被系統重新啓動? – Karakuri

+0

4.1果凍豆。是的,服務約4秒後重新啓動通知 – dooplaye

+0

也我測試其他應用程序。除Poweramp玩家外幾乎所有人都有相同的行爲。他只是忽略了殺人 – dooplaye

回答

2

爲防止服務殺害發現一個黑客(其實我的確在這裏讀過)

@Override 
    public void onTaskRemoved(Intent rootIntent) { 
      Intent intent = new Intent(this, DummyActivity.class); 
      intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
      startActivity(intent); 
    } 

DummyActivity:

public class DummyActivity extends Activity { 
    @Override 
    public void onCreate(Bundle icicle){ 
     super.onCreate(icicle); 
     finish(); 
    } 
} 

就是這樣。但是有這個技巧的副作用 - 與最近用過的面板會立即隱藏,你刷卡的

+0

即時通訊開始我的活動從我報警onRecieve了,我想我的活動應該出現在最近名單,但只要有我== 2的狀態,因爲我== 2那麼這活動應該完成並從最近的列表中刪除,如果我使用xml屬性,那麼它是從最近的列表中完全隱藏 – Erum