Android应用启动速度优化
作者:zgz345 时间:2023-03-18 04:07:44
开发Android应用中,随着功能越来越多,启动速度越来越慢。有没有办法让自己应用启动速度快一点呢?
方法是人想出来的。先说说我的实现方法:
1 将onCreate 中初始化的内容,移动到线程中做初始化,加载等
2 初始化完成之后,通过Handler发送消息,
3 Hander 中收到消息后,再初始化完整界面。
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); //设置layout布居
// 使用线程异步加载数据,不阻塞界面。
new Thread(){
@Override
public void run() {
// TODO Auto-generated method stub
super.run();
initData();
}
}.start();
}
private final static int MSG_INIT_VIEW = 0xA00;
private final Handler handler = new Handler() {
@Override
public void dispatchMessage(Message msg) {
switch (msg.what) {
case MSG_INIT_VIEW:
initView();
break;
default:
super.dispatchMessage(msg);
}
}
};
private void initData(){
try {
Thread.sleep(5000);// 模拟加载数据需要 5秒
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//数据加载完成,可以更新界面了
handler.sendEmptyMessage(MSG_INIT_VIEW);
}
private void initView(){
//TODO 刷新界面
}
}
标签:Android,启动,优化
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Java方法参数传递机制原理解析
2022-04-16 19:10:46
![](https://img.aspxhome.com/file/2023/2/69672_0s.png)
Java Web使用简单的批处理操作(记事本+Tomcat)
2021-08-13 10:08:33
![](https://img.aspxhome.com/file/2023/4/66074_0s.png)
java自定义序列化的具体使用
2022-02-06 06:27:12
![](https://img.aspxhome.com/file/2023/1/64951_0s.jpg)
SpringBoot如何使用Fastjson解析Json数据
2023-11-25 11:55:58
![](https://img.aspxhome.com/file/2023/1/60041_0s.png)
Jmeter后置处理器实现过程及方法应用
2023-08-26 17:22:41
![](https://img.aspxhome.com/file/2023/7/125327_0s.png)
IDEA调试技巧条件断点实现步骤详解
2023-11-24 16:02:42
![](https://img.aspxhome.com/file/2023/1/70501_0s.png)
详解如何在C#中使用投影(Projection)
2023-03-28 09:14:15
![](https://img.aspxhome.com/file/2023/1/119551_0s.png)
简介Android 中的AsyncTask
2022-06-14 17:06:57
Android开发手册TextView属性实现效果盘点
2022-03-10 09:29:53
![](https://img.aspxhome.com/file/2023/2/109192_0s.jpg)
Android App中ViewPager与Fragment结合的一些问题解决
2023-08-02 22:22:43
![](https://img.aspxhome.com/file/2023/2/137202_0s.jpg)
java打印正弦曲线示例
2022-05-04 00:48:56
![](https://img.aspxhome.com/file/2023/5/129115_0s.jpg)
C#巧用DateTime预设可选的日期范围(如本年度、本季度、本月等)
2022-09-19 11:06:41
![](https://img.aspxhome.com/file/2023/2/125992_0s.gif)
关于Java实现HttpServer模拟前端接口调用
2021-07-10 07:44:17
![](https://img.aspxhome.com/file/2023/4/88054_0s.png)
Java之SpringBoot自定义配置与整合Druid
2022-09-28 06:23:06
![](https://img.aspxhome.com/file/2023/7/63007_0s.png)
Jenkins Host key verification failed问题解决
2021-07-14 12:53:41
Android开发仿映客送礼物效果
2023-03-24 01:11:12
![](https://img.aspxhome.com/file/2023/3/93293_0s.gif)
Java线程中sleep和wait的区别详细介绍
2021-08-27 02:23:12
Java之int和string类型转换详解
2023-11-06 04:10:06
java异常处理机制示例(java抛出异常、捕获、断言)
2022-11-16 21:26:13
![](https://img.aspxhome.com/file/2023/2/71952_0s.jpg)
Android实现字母雨的效果
2023-12-13 02:26:33
![](https://img.aspxhome.com/file/2023/7/139037_0s.gif)