I have to call a Async Task with listener from the TimerTask eack 1.5 seconds.When I tried to do that I'm getting an exception "java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare().". Please h开发者_运维知识库elp us to solve this issue.
Following is the piece of code I use..
Timer t = new Timer();
TimerTask scanTask = new TimerTask()
{
@Override
public void run()
{
new BgTask((BgTaskListener)this).execute("","currentState");
}
};
t.schedule(scanTask, 1500, 1500);
Here BgTask id the AsyncTask class.
if you are in context of activity then this must work
runOnUiThread(new Runnable()
{
@Override
public void run()
{
new BgTask((BgTaskListener)this).execute("","currentState");
}
});
精彩评论