一、定时循环执行
private static Handler handler = new Handler();
private static Runnable runnable = new Runnable(new Action(run));
private static void run()
{
//renwushow.PostInvalidate();//刷新内容
handler.PostDelayed(runnable, 1000 * 3);
}
注意:在当前页面销毁时停止执行的活动
/// <summary>
/// activity销毁
/// </summary>
protected override void OnDestroy()
{
handler.RemoveCallbacks(runnable); //停止刷新
base.OnDestroy();
}
二、定时执行一次
public class mytimetask : TimerTask
{
public override void Run()
{
//要执行的活动,例如等待页面加载完成后执行相应的操作
}
}
Java.Util.Timer timer = new Java.Util.Timer();
timer.Schedule(new mytimetask(), 1000);