java - Difference when starting timer inside service and activity -


i want have periodically task should run every 30 seconds. i'm using scheduledthreadpoolexecutor or timer

 scheduledthreadpoolexecutor executor = new scheduledthreadpoolexecutor(1);         executor.schedulewithfixeddelay(new mytask(), 0, 30000, timeunit.milliseconds);  class mytask implements runnable {         @override         public void run() {         }         }    

here timer

timer timer = new timer();         timer.schedule(new timertask() {             @override             public void run() {                 // here             }         }, 0, 30000); 

my question is: there differences if start above code inside service/intentservice or inside 1 activity. actions same or start inside service better.

if want run task when app in backgroud should use service or if want run in when app in front may use in activity


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -