Timer和TimerTask使用完整示例
2014-02-19 16:32
344 查看
MainActivity如下:
main.xml如下:
package cc.test; import java.util.Timer; import java.util.TimerTask; import android.app.Activity; import android.os.Bundle; /** * Demo描述: * Timer和TimerTask使用完整示例 */ public class MainActivity extends Activity { private Timer mTimer; private TimerTask mTimerTask; private int count=0; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); init(); } private void init() { mTimer = new Timer(); mTimerTask = new TimerTask() { @Override public void run() { count++; System.out.println("---> count=" + count); if (count == 15) { mTimer.cancel(); System.out.println("---> 取消定时任务"); } } }; //开始一个定时任务 mTimer.schedule(mTimerTask, 2000, 1500); } }
main.xml如下:
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#ffffff" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Timer和TimerTask使用完整示例" android:layout_centerInParent="true" android:textColor="#111111" /> </RelativeLayout>
相关文章推荐
- Timer和TimerTask使用完整示例
- 定时任务:Java中Timer和TimerTask的使用
- java类Timer和TimerTask的使用
- 在AndroidManifest中使用meta-data保存数据完整示例
- 使用Timer,TimerTask完成播放视频点击显示控制台
- 在JavaScript中使用timer示例
- Spring MVC中使用Swagger生成API文档和完整项目示例Demo,swagger-server-api
- ListPopupWindow使用完整示例(二)——自定义ListPopupWindow
- php使用环形链表解决约瑟夫问题完整示例
- struts使用list提交多行表单(提供完整示例)
- 定时任务:Java中Timer和TimerTask的使用
- Python编程使用tkinter模块实现计算器软件完整代码示例
- 一小时教程 MySQL从安装到使用 详细步骤 完整图文示例练习教程 学习笔记
- 使用Filter验证用户是否登陆,完整示例
- Timer 与 TimerTask 示例
- PriorityQueue(优先队列)使用完整示例
- Timer 和TimerTask 使用
- 通过完整示例来理解如何使用 epoll
- C#多线程编程之:Timer(定时器)使用示例
- 定时任务:Java中Timer和TimerTask的使用