Hi,
Please let me know if the following is okay:
1. Fire alarm for every 5 minutes using Alarm Manager
2. Response- Start a service that polls server
3. After polling, new alarm is set and service shuts down.
Should I also use WakeLock in my code?
https://github.com/commonsguy/cwac-wakeful
Thank you!
On Tuesday, October 9, 2012 1:04:40 PM UTC+3, skink wrote:
>
>
>
> Archana wrote:
> > Should I have the alarm manager as a service?(as I want the application
> to
> > be executed always)...
> >
> > Here is my service:
> >
> > public class PollService extends Service
> > {
> > private PendingIntent pendingIntent;
> > private AlarmManager alarmManager;
> > private Calendar calendar;
> > @Override
> > public IBinder onBind(Intent arg0) {
> > return null;
> > }
> > @Override
> > public boolean onUnbind(Intent intent) {
> > return super.onUnbind(intent);
> > }
> >
> > @Override
> > public void onCreate() {
> > Toast.makeText(getApplicationContext(), "Service Started",
> > Toast.LENGTH_SHORT).show();
> > alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
> > Intent myIntent = new Intent(this, PollService.class);
> > pendingIntent = PendingIntent.getService(this, 0, myIntent, 0);
> > calendar = Calendar.getInstance();
> > }
> > @Override
> > public void onStart(Intent intent, int startId) {
> > super.onStart(intent, startId);
> > calendar.setTimeInMillis(System.currentTimeMillis());
> > calendar.add(Calendar.MILLISECOND, 300000);// Polling for every 5
> minutes
> > alarmManager.set(AlarmManager.RTC_WAKEUP,
> > calendar.getTimeInMillis(),pendingIntent);
> > }
> > @Override
> > public void onDestroy() {
> > super.onDestroy();
> > alarmManager.cancel(pendingIntent);
> > }
> > }
> >
> > But where do I define connecting to the server and getting the contents?
> >
> > Thank you.
> >
>
> use IntentService as a sa base base class, read its docs and
> everything will be obvious
>
> pskink
>
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en