dracula
dracula

Reputation: 4473

android service restarts itself on application killed

I am developing an applicaton which communicates with my service via receivers.

Service Code

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(LOCATION_UPDATE);
    mBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            receiverWorks(intent);
        }
    };
  this.registerReceiver(mBroadcastReceiver, intentFilter);
  return START_STICKY;
    }

Service's Manifest declaration

    <service
        android:name="com.test.IService"
        android:enabled="true"
        android:label="IService"
        android:process=":iservice" >
    </service>

Problem is that it restarts itself after application (my application which uses this service) is being killed. How can i prevent this ? Tried to remove android:process but nothing changes.

Waiting for you help.

Thanks

Upvotes: 5

Views: 8234

Answers (1)

Shrikant Ballal
Shrikant Ballal

Reputation: 7087

The service restarts itself because you are returning START_STICKY in onStartCommand()

You need to return start_not_sticky instead.

For more info, please read this: START_STICKY and START_NOT_STICKY

Upvotes: 8

Related Questions