Android 延时执行操作方法
2016-03-21 14:20
375 查看
下面是三种方法:
一、线程
[html] view plaincopy
1. new Thread(new Runnable(){
2. public void run(){
3. Thread.sleep(XXXX);
4. handler.sendMessage();----告诉主线程执行任务
5. }
6. }).start
二、延时器
[html] view plaincopy
1. TimerTask task = new TimerTask(){
2. public void run(){
3. //execute the task
4. }
5. };
6. Timer timer = new Timer();
三、android消息处理
[html] view plaincopy
new Handler().postDelayed(new Runnable(){
public void run() {
//execute the task
}
}, delay);
推荐使用第三种
一、线程
[html] view plaincopy
1. new Thread(new Runnable(){
2. public void run(){
3. Thread.sleep(XXXX);
4. handler.sendMessage();----告诉主线程执行任务
5. }
6. }).start
二、延时器
[html] view plaincopy
1. TimerTask task = new TimerTask(){
2. public void run(){
3. //execute the task
4. }
5. };
6. Timer timer = new Timer();
三、android消息处理
[html] view plaincopy
new Handler().postDelayed(new Runnable(){
public void run() {
//execute the task
}
}, delay);
推荐使用第三种
相关文章推荐
- Android中如何检测重力感应变化:Sensor和SensorManager
- 自定义闪烁的TextView
- Android 圆角边框的实现方式汇总
- [better practice系列]Android中自定义全局变量、常量并采用高效的维护管理(一)
- Android——支付宝
- 你应该知道的那些Android小经验 (转载)
- android ViewPager适配器
- 【入门篇】Android学习笔记——常用布局
- android多国语言文件夹
- Android 圆角 ImageView类可设置弧度(代码简单)
- 【入门篇】Android学习笔记——常用布局
- SDK 组件 Qupaisdk 启动出错,错误消息为 [Qupaisdk], the android stack error message is Fail to start the plugin, which is caused by Failed resolution of: Lcom/duanqu/qupai/recorder/R$array;
- Android Clipboard(复制/剪贴板)
- Android-绘制爱心
- [引用]Android通过百度地图API用Service和Alarm在后台定时获取地理位置信息
- android studio 自定义路径安装报错"You are attempting to install the android SDK
- Android 主题的更换支持在线主题
- 2015总结和Android开发工程师简历的书写
- Android之ContentProvider与ContentResolver
- 腾讯 Bugly for Xamarin Android 的插件