我試圖在啓動時啓動我的服務,但我一直收到1245-1263/? I/ActivityManager﹕ Waited long enough for: ServiceRecord{3d8aa3b0 u9 myPackage/.myService}
異常。如何設置服務的優先級以確保它在啓動時啓動?
我看過這個:My service always getting Waited long enough for: ServiceRecord error in Kitkat 它告訴我,ActivityManager正在啓動我的服務暫停。我已通過日誌聲明確認我的接收器確實正在工作。這是在任何情況下的代碼有興趣:
public class PhoneStateReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.d("OnStartUp", "Service is about to be started");
Intent myIntent = new Intent(context, myService.class);
context.startService(myIntent);
}
}
那麼,我該怎麼設置我的服務的優先級爲「必要的」,這樣的Android確保它啓動?我看了這個:How to set the priority of android service?,但它涉及重新啓動服務,而不是初始啓動。
這裏是我的清單的相關位:
<receiver android:name=".PhoneStateReceiver"
android:enabled="true"
android:label="PhoneStateReceiver"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
<service
android:name=".myService"
android:enabled="true"
android:exported="true" >
</service>
在此先感謝。
我有,我想。我將編輯問題以顯示我的清單。 –