On Sat, Jun 4, 2016 at 5:50 AM, Neilz <neilhorn...@gmail.com> wrote:

> Hi. I need a background task to run every minute.
>

https://developers.google.com/android/reference/com/google/android/gms/gcm/GcmNetworkManager


> I have no need for a user interface, although I understand that I must
> still declare a launcher activity
>

No, you don't.


> I'm confused between the use of AlarmManager, Receivers and Services. So
> far, I've scheduled a repeating alarm, which passes a class called
> AlarmReceiver in its Intent. AlarmReceiver extends BroadcastReceiver, and
> the onReceive() method successfully fires every minute, even if I kill the
> activity, which is exactly what I want.
>
> However, at no point am I using a class which extends Service or
> IntentService, which when I look around at other people's examples, seems
> to be what everyone does when they want a task to run as a background
> service. Am I doing something wrong? Should I be calling a Service class
> from my BroadcastReceiver instead of doing the work there?
>

Probably. You don't really need a receiver in this case. The point of a
receiver is to get notified of specific events happening either in you app
or throughout the system. If all you're interested in is doing some work
every 1 minute, then you don't need the receiver. The alarm manager's
intent that is fired when the alarm goes off can just be an intent to
launch an a(n) (Intent)Service that does that work.

-------------------------------------------------------------------------------------------------
TreKing <http://sites.google.com/site/rezmobileapps/treking> - Chicago
transit tracking app for Android-powered devices

-- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-developers+unsubscr...@googlegroups.com.
To post to this group, send email to android-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/android-developers/CANCScgiOHsZaFRmbDOF28c5sMLTWxWTwou65LmwZrLjoOgjTjQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to