android - Service Is Looping In Crazy Way -


i've made service set something, added log , timer, timer delay taken form sharedpreferences value, value returning 5 minutes, problem service looping in crazy way, it's not 1 sec delay, nope .. it's less second delay , it's outputting log message .

and mention, i'm using same code service, have problem in service, codes :

manifest :

        <service         android:name=".services.servicetest"         android:enabled="true"         android:exported="false" >     </service> 

switch starts service :

            intent broadcastintent = new intent(getactivity(),receivertest.class);                 broadcastintent.setaction(packagetest+"startservice");                 getactivity().sendbroadcast(broadcastintent); 

receiver takes action, in if statement , runs service via intent in following way :

        intent servicetestintent = new intent(context, servicetest.class);         context.startservice(servicetestintent); 

the service :

    @override public int onstartcommand(intent intent, int flags, int startid) {     sharedpreferences preference = preferencemanager.getdefaultsharedpreferences(this);     int delay= preference.getint("value", 2 * 60 * 1000);     mytimer = new timer();     new thread()     {         public void run() {             mytimer.schedule(new timertask() {                 @override                 public void run() {                     log.i(fragment.tag,"message test");                 }             }, delay, delay);         }     }.start();      return start_not_sticky; } 

the delay returns 5 minutes (5*60*1000) , store in sharedpreferences, when log value says 5 minutes, it's correct time, though default 2 minutes, service loops directly , output message .

receiver :

        if(intent.getaction().equals(mainactivity.package+"startservice"))     {         context.startservice(serviceintent);     } 

update : thing is, got 3 other services different receivers, when switch of them, test service launched, though didn't start or reference it, or related in other switches . i've tried rebooting/app full deletion using root app remover .

add log statement show delay. either delay value wrong or service being started multiple times:

@override public int onstartcommand(intent intent, int flags, int startid) {     sharedpreferences preference = preferencemanager.getdefaultsharedpreferences(this);     final int delay= preference.getint("value", 2 * 60 * 1000);     log.i(fragment.tag, string.format("onstartcommand(): delay=%d", delay));     final timer mytimer = new timer();     new thread()     {         public void run() {             mytimer.schedule(new timertask() {                 @override                 public void run() {                     log.i(fragment.tag, "message test");                 }             }, delay, delay);         }     }.start();      return start_not_sticky; } 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -