2014-09-25 97 views
0

在android應用程序中,如果我保存正在運行的服務的意圖。我該如何重新啓動服務? 我希望它再次運行onStartCommand函數。在Android中重新啓動服務

感謝

回答

1

onStartCommand回報START_STICKY

public int onStartCommand(Intent intent, int flags, int startId){ 
    super.onStartCommand(intent, flags, startId); 
    return START_STICKY; 
} 

文檔鏈接:http://developer.android.com/reference/android/app/Service.html

+0

這是行不通的。 – ida 2014-09-25 14:50:40

+0

我有代碼在一個地方,並在其他服務,這是爲了安排我開始服務停止並啓動服務,以便有OnStartCommand調用。那是問題嗎? – ida 2014-09-25 14:52:40

+0

「稍後,系統將嘗試重新創建服務,因爲它處於啓動狀態,所以它將保證在創建新服務實例」從官方文檔!「中調用onStartCommand(Intent,int,int)!但我認爲這不完全是你想要的!你的問題有點令人困惑 – Pavlos 2014-09-25 14:54:50