Podczas uruchamiania aplikacji uruchom tylko usługę w tle

Chcę zacząć od uruchomienia usługi dopiero po uruchomieniu aplikacji. Oto mój kod:

Moja klasa usług:

public class MyService extends Service {
 @Override
  public int onStartCommand(Intent intent, int flags, int startId) {

     Log.i("LocalService", "Received start id " + startId + ": " + intent);

   // We want this service to continue running until it is explicitly
   // stopped, so return sticky.
   return START_STICKY;
  }

@Override
public IBinder onBind(Intent intent) {
    // TODO Auto-generated method stub
    return null;
}
}

Moja klasa BroadcastReceiver:

public class MyServiceReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
    Intent service = new Intent(context, MyService.class);
    context.startService(service);
}
}

I mój plik AndroidManifest:

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />

<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" >

    <service
      android:name=".MyService"
      android:label="@string/app_name"
      android:enabled="true"
      android:process=":my_process" >
    </service>

    <receiver 
        android:name=".MyServiceReceiver"
        android:enabled="true" >

        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <action android:name="android.intent.action.BOOT_COMPLETED"/>
            <category android:name="android.intent.category.HOME"/>
        </intent-filter>
    </receiver>

</application>

Chcę uruchomić moją usługę po uruchomieniu aplikacji (jest instalowana po raz pierwszy) i po uruchomieniu urządzenia.

P.S. Jeśli kod jest prawidłowy, może muszę skonfigurować konkretną konfigurację przycisku „run” zaćmienia? Jeśli spróbujesz utworzyć nową konfigurację, nie mogę niczego wybrać w akcji „Uruchom”, ponieważ moja aplikacja nie ma aktywności i muszę wybrać opcję „Nic nie rób”.

Dzięki

questionAnswers(1)

yourAnswerToTheQuestion