android – Eternal Handler in Service


The task is to check the text of one post on the VK wall every 10 seconds in the service.
I do it via Runnable() :

public void useHandler() {
    mHandler = new Handler();
    mHandler.postDelayed(mRunnable, 10000);

How heavy is it for the application and how can this be done correctly?


Runnable task = new Runnable() {
    public void run() {
    //проверка записи на стене ВК

ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
scheduler.scheduleAtFixedRate(task, 0, 10, TimeUnit.SECONDS);

Runnable will be executed every 10 seconds. You can terminate the work by calling scheduler.shutdown() .

Scroll to Top