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.
Starting a runnable every few seconds is gonna have some lag no matter what way you slice it, no? I don't see why a Handler shouldn't work just fine.
You might be experiencing some troubles though because you have
void startRepeatingTask()
{
m_handlerTask.run();
}
Instead, you should use the Handler and do something like:
void startRepeatingTask()
{
m_handler.post(m_handlerTask);
}
(As an aside, the convention in Java is to use camel case, not snake case. So it should be mHandler, not m_handler, etc. Just telling you because it might make your code easier to read for some.)