我正在嘗試創建一個將在後臺處理文件I/O的服務。更新數據的活動將綁定到服務並調用服務的方法來執行I/O。我正在使用Android文檔進行指導。Android服務從未出現過 - onStartCommand()未調用
但是,我的服務似乎並不想開始。在我的活動的onCreate()方法,我有:
Intent smsIntent = new Intent(this, SurveyManagerService.class);
String surveyFilename = getIntent().getStringExtra("surveyFilename");
System.out.println(startService(smsIntent)); //testing if it starts
SurveyManagerServiceConnection connection = new SurveyManagerServiceConnection();
sms = connection.getSurveyManagerService();
在線路3的logcat輸出ComponentInfo對象,所以它會出現該服務被創建;但是,短信爲空。此外,SurveyManagerService onStartCommand()方法似乎從來沒有被稱爲:
@Override
public int onStartCommand(Intent intent, int flags, int startId)
{
System.out.println("starting service");
Toast.makeText(this, "service starting", Toast.LENGTH_SHORT).show();
openSurveyFromIntent(intent);
return START_REDELIVER_INTENT;
}
我從來沒有看到任何logcat中「啓動服務」輸出,也不敬酒出現。
<service android:name=".SurveyManagerService" android:exported="false" android:enabled="true">
</service>
我失去了一些東西很明顯:
我的服務我的表現爲申報?讓我知道我應該提供哪些其他信息來診斷問題。
也許你的服務反覆崩潰聲明你的服務? – Reno
我該如何去測試它是否在onStartCommand()的第一行之前崩潰?謝謝。我忘了說onCreate()方法也有一個System.out.println測試,它永遠不會被調用。 – Spinner