android中延迟执行某个任务
2016-07-13 09:43
447 查看
android中延迟执行某个任务
android App开发在某些情况下需要有延时功能,比如说App首页显示定格3秒,然后自动跳到登录页的情况,这就好比是一个预加载,但是这个预加载可能瞬间就完成了,撑不到3秒钟,这是就要求你做延时处理。下面是三种方法:
一、线程
[html] view
plain copy
1. new Thread(new Runnable(){
2. public void run(){
3. Thread.sleep(XXXX);
4. handler.sendMessage();----告诉主线程执行任务
5. }
6. }).start
二、延时器
[html] view
plain copy
1. TimerTask task = new TimerTask(){
2. public void run(){
3. //execute the task
4. }
5. };
6. Timer timer = new Timer();
timer.schedule(task, delay);
![](http://static.blog.csdn.net/images/save_snippets.png)
三、android消息处理
[html] view
plain copy
new Handler().postDelayed(new Runnable(){
public void run() {
//execute the task
}
}, delay);
推荐使用第三种
相关文章推荐
- 文章标题
- Android实现无标题栏全屏的方法
- 知识分享
- Android EditText 实现监听实例
- Android中View和ViewGroup介绍
- Android Hook框架Xposed原理与源代码分析
- Android在多个Activity间传递对象及对象数组
- android multimedia的代码边读边记
- [Android] Android开发优化之——对Bitmap的内存优化
- Android 通过JSON保存数据
- Android学习记录(二十六)-Android toolbar使用遇到的坑。
- Android 自定义下拉刷新列表
- Android自定义控件 资源博客集合
- android平台框架原理
- Android生成带LOGO图片二维码的方法
- Android 自定义属性类型
- Android常用工具类
- Android Volley完全解析
- android annotation abstract
- [Android]Context泄露之谜:Handle & 内部类