1

As the title suggests, I've got a service that adds an icon on top of all other screens...kind of what Facebook Head or Link Bubble does. That works fine on most devices, the icon is always there.

On a Samsung S3, however, whenever I press the device's Home icon, the icon disappears and I think the service stops. Why is that?

devguy
  • 2,336
  • 5
  • 27
  • 31
  • `adds an icon` you mean sends a persistent notification? – njzk2 May 21 '14 at 17:45
  • no, it adds an ImageView/Button directly on the screen, on top of any other activity/app. Just like Facebook's Chat Head: http://www.piwai.info/chatheads-basics/ – devguy May 21 '14 at 17:47
  • then you problem lies in the way your service works. – njzk2 May 21 '14 at 17:51

2 Answers2

1

I guess you need a background service...

As for services they run until the activity which started it is running so as soon as its parent is killed its too getting killed...

( as far as i know )

You can try to start a service during onboot etc.. which will run in global context. During development you can use something like ringermode change or network change reciever and start the service from there.

Also to be confirmed your service is running or not you can goto settings -> Apps -> Running you will see if your service is running or not.

Thanks

Ahmad
  • 437
  • 1
  • 4
  • 12
0

Looks like the service is stopped when the main app that stared it is closed...which can happen at different times on different devices. More info here: Android Service Stops When App Is Closed

More info:

  • when the activity that started the service is closed (by the user, or by the system), the service is stopped as well. However, it starts automatically again as soon as possible (how fast depends on the device)
  • my service was already a background service...and in order to be kept always running, it should have been marker as foreground instead (with startForeground). Problem is that a sticky notification needs to be always present in the notification area, which would be very annoying.

In the end, I think the current behaviour works fine for most current devices that don't automatically close an app when the activity is put in background...and that anyway are able to restart the service automatically shortly after stopping the service because of that. If that wasn't enough, then I'd had to use startForeground.

Community
  • 1
  • 1
devguy
  • 2,336
  • 5
  • 27
  • 31