0

I'm using a receiver to start a service upon ACTION_SCREEN_OFF, but I'm wondering if it's better, battery wise, to just start the activity (that the service starts) directly from the broadcastreceiver?

The app acts as a lockscreen and must not be killed, but I don't want a redundant service slowly killing the users battery in the background.

Carl
  • 249
  • 2
  • 5
  • 13

1 Answers1

0

It's not clear why you would need a service here. It's probably because you didn't provide too many details. Yes, even if service is not doing much it's going to consume resources such as memory and battery. Since it's not doing much, the resource consumption will probably be very small, but it would be cleaner in my view just start an activity from broadcastreceiver as described here:

Start Activity inside onReceive BroadcastReceiver

Community
  • 1
  • 1
Oleg Gryb
  • 5,122
  • 1
  • 28
  • 40
  • Even I don't know why I'm using a service. I've never had a service be anything but complex, but this time it's just really simple. That's why I'm asking now if it's more batteryfriendly to use a broadcast instead of a service. I put up a quick app with AIDE (Android IDE) and it seems like it is a lot slower at responding than a service. And this is just a simple activity with "Hello world" in it. Unfortunately. – Carl Jul 18 '14 at 21:37
  • I'm not sure why app is slower than service, probably because the app is cached and needs to be loaded back when receives an intent. Why don't you go to Settings->More->Battery on your device and check how much battery your service is consuming? If it's acceptable and response time is really better with service - go for it. – Oleg Gryb Jul 18 '14 at 22:05
  • Actually, you've just added a response time to the criteria of choosing between an app and service. You should probably edit your initial question, because response time maybe a big differentiating factor. – Oleg Gryb Jul 18 '14 at 22:10