Let's say that I want to perform some action every 10 seconds and it doesn't necessarily need to update the view.
The question is: is it better (I mean more efficient and effective) to use timer with timertask like here:
final Handler handler = new Handler();
TimerTask timertask = new TimerTask() {
@Override
public void run() {
handler.post(new Runnable() {
public void run() {
<some task>
}
});
}
};
timer = new Timer();
timer.schedule(timertask, 0, 15000);
}
or just a handler with postdelayed
final Handler handler = new Handler();
final Runnable r = new Runnable()
{
public void run()
{
<some task>
}
};
handler.postDelayed(r, 15000);
Also I would be grateful if you could explain when to use which approach and why one of them is more efficient than another (if it actually is).
TimerTask
notHandler
. – Amitosis