开发者

How to call AyncTask with listener from a TimerTask in android?

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");
        }
    });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜