0

I´ve got a background service, which pushes notifications. When you click on the notifications, my activity is opened, but the problem is, the onStartCommand is called then again, which propably could invoke another notification, which means I have a loop.

I´m using

    @Override
public int onStartCommand(Intent intent, int flags, int startId) {
    return Service.START_NOT_STICKY;
}

also tried Service.START_STICKY with no effect.

In my manifest:

        <service
        android:name=".notification.NotificationService"
        android:exported="false"></service>

what could cause a recall of onStartCommand?

Marian Klühspies
  • 15,824
  • 16
  • 93
  • 136
  • http://stackoverflow.com/questions/6399075/android-service-startservice-is-called-multiple-times-and-causes-value-mixup – Tourki Sep 15 '13 at 21:54

1 Answers1

0

Check your Activity code, sounds like your accidentally starting the Service.
There are some situations where this could happen like it may be killed by the system if it is under heavy memory pressure. If this happens, the system will later try to restart the service.

There Is another possibility this might happen. If you rotate your device your Activity will be killed and restarted all according to Android official docs Activity . Your Service will be launched again. Read the docs, save some time and headache. On this link Android official docs Activity, scroll down 2 laps and you see a picture of the lifecycle.

Erik
  • 5,039
  • 10
  • 63
  • 119