java - Correct way to execute periodic background tasks -


so need execute periodic tasks in background, if app closed. did creating service , restarting in period of time, using alarmmanager:

public class myservice extends service {     @override     public int onstartcommand(intent intent, int flags, int startid)     {         log.i("myservice","on command!");          stopself();          return start_not_sticky;      } 

as can see, service intended started not sticky, job , stop immediately.

shedule (1 second fast testing only, causes wakelock):

@override     public void ondestroy()     {         alarmmanager alarm = (alarmmanager)getsystemservice(alarm_service);         alarm.set(                  alarm.rtc_wakeup,                 system.currenttimemillis() + (1000),                 pendingintent.getservice(this, 0, new intent(this, myservice.class), 0)         );     } 

my service start on boot or on alarm (each 1 second currently). however, i'm not sure if it's correct way want. noticed, 3rd party apps use sticky services , reside in memory time.

so question is, when should use sticky service?


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

node.js - Using Node without global install -

php - CakePHP HttpSockets send array of paramms -