0

I have some doubts about the properly implementation of services and broadcastreceivers.

I have made an app in which there are novelties. Some novelties are important, so in the DB they have a field in which they store if they are important or not. If they are, the app should check if the last novelty seen by the user is the latest one. This should trigger a notification if there are important novelties that were not seen by the user.

I know how to show notifications in Android, and I have a Method in my Web Service which shows if the user has novelties to read or not. I just need to know how to make my app consume this at random times and without being opened (just like Whatsapp does). I have read the BroadcastReceiver and Services documentation, but I don't know how to do this in an efficient way. Do I make a BroadcastReceiver to call a Service at the Phone's Boot? And make this Service to check at random amounts of time?

Thanks a lot!

Ronan
  • 1
  • 2

1 Answers1

0

What you want is a foreground service with a BroadcastReceiver that starts the service on boot. View this answer and make the required changes to use startForeground() instead of startService.

Community
  • 1
  • 1
alzee
  • 1,393
  • 1
  • 10
  • 21
  • Hm... I don't want a service which shows a notification when it's running. I wan't a silent service which, if it finds new novelties, shows a notification. Could I use a Normal Service (without the startForeground)? – Ronan Dec 13 '15 at 22:38
  • Yes, you can do that as well. You can even have the normal service start the notification service, or anything else you can imagine. – alzee Dec 13 '15 at 22:51
  • Hi, I have researched and found that GCM is the best option for this. You can't have a background service running and checking each minute in the server: that eats out the battery of the phone and other resources. – Ronan Jan 07 '16 at 05:44