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
Post a Comment