Android应用启动慢的问题
16lz
2021-01-26
原因
因为在Application的onCreate有很多第三方平台的初始化工作,所以造成启动慢
解决方法
创建一个子线程来处理,最好的是使用IntentService来启动子线程进行处理,因为IntentService在处理完成后会自动停止,不用手动销毁线程。
private static final String ACTION_INIT_WHEN_APP_CREATE = "com.demo.app.service.action.INIT";@Overrideprotected void onHandleIntent(Intent intent) { if (intent != null) { final String action = intent.getAction(); if (ACTION_INIT_WHEN_APP_CREATE.equals(action)) { performInit(); } }}
在创建一个启动service的方法供调用
public static void start(Context context) { Intent intent = new Intent(context, InitializeService.class); intent.setAction(ACTION_INIT_WHEN_APP_CREATE); context.startService(intent);}
更多相关文章
- Android(安卓)adb启动任意app的几种方式
- 消息处理机制 —Handler/Thread/Looper & MessageQueue
- android HandlerThread源码解析
- Android中的几种多线程实现
- Android(安卓)Toast 用法总结
- Android界面刷新
- 走进Java Android(安卓)的线程世界(三)Hander消息机制
- Android(安卓)进阶——Framework 核心四大组件之跨进程共享组件C
- Android(安卓)双开沙箱 VirtualApp 源码分析(四)启动插件 Service