I am trying to add a service to my Android application, but the service does not start at all. I added it to my Android manifest so that it starts in its own process and creates a broadcast that should start the service after BOOT_COMPLETED.
Here is part of my manifest
<service android:process=":attachServiceBackground" android:name=".AttachService" android:icon="@drawable/camera" android:label="@string/attachServiceName" /> <receiver android:name="AttachmentStartupReceiver" android:process=":attachServiceBackground"> <intent-filter > <action android:name="android.intent.action.BOOT_COMPLETED"></action> </intent-filter> </receiver>
my service ... just added a log
public class AttachService extends Service { private static final String TAG = AttachService.class.getSimpleName(); @Override public IBinder onBind(Intent intent) { return null; } @Override public void onCreate() { super.onCreate(); Log.d(TAG, "onCreate service"); } @Override public void onDestroy() { super.onDestroy(); Log.d(TAG, "onDestroy"); } @Override public int onStartCommand(Intent intent, int flags, int startId) { Log.d(TAG, "onStartCommand"); return super.onStartCommand(intent, flags, startId); } }
And my BroadCastReceiver
public class AttachmentStartupReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Intent attachSvc = new Intent(context, AttachService.class); context.startService(attachSvc); } }
I do not see that the service starts after the device boots up, there is no "oncreate service" in the logs, and I also looked in "Settings-> Applications-> Running Services". Does anyone know what I did wrong?
thanks
source share