I want to create a thread in an Android service that runs every X seconds
I am currently using , but the postdelayed method seems to really lag out my app.
Here is how I run a repeating thread, as you'll see it loops every 1 second. I see no lag with this method.
final Thread t = new Thread(new RepeatingThread());
t.start();
And the class:
import android.os.Handler;
public class RepeatingThread implements Runnable {
private final Handler mHandler = new Handler();
public RepeatingThread() {
}
@Override
public void run() {
mHandler.postDelayed(this, 1000);
}
}