1
我有一個IntentService,它在啓動時啓動並保持在後臺運行。沒有啓動器Activity,IntentService由廣播接收器調用。它適用於2.3.4和4.0.4設備,但不適用於4.2.2。也許我的廣播接收器沒有在設備上被觸發?Android IntentService在啓動時不會啓動
清單:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="br.com.xxx"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<receiver android:name="br.com.xxx.RastreadorBroadcastReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<service
android:name="br.com.xxx.ObtainAndPostLocationService"
android:exported="true">
</service>
</application>
</manifest>
RastreadorBroadcastReceiver:
package br.com.xxx;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class RastreadorBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Intent startServiceIntent = new Intent(context, ObtainAndPostLocationService.class);
context.startService(startServiceIntent);
}
}
您的Receiver是否獲得了意向?我想,你的onReceive方法會被調用嗎? – edoardotognoni
我無法進行調試,因爲它不是一項活動。我如何檢查? – Piovezan
在創建startServiceIntent之前,只需添加:Log.d(「DEBUG」,「Creating the intent」);並查看該字符串是否寫入logcat – edoardotognoni