现在的位置: 首页 > 综合 > 正文

Android定时任务

2013年05月30日 ⁄ 综合 ⁄ 共 285字 ⁄ 字号 评论关闭

可以用Handler实现一个:

private Runnable yourRunable = new Runnable() 
{
    @Override
    public void run() 
    {
    //你要做的事
	handler.postDelayed(this, 5000);  
    }
}

开启定时器:

handler.postDelayed(yourRunable, 5000);

 

记得在onDestory()时把它关掉:

@Override
protected void onDestroy() 
{
    //停止定时任务
    handler.removeCallbacks(yourRunable);
    super.onDestroy();
}

 

抱歉!评论已关闭.