主要是解决在应用初始化过程太久初次打开可能造成黑屏的问题。
当然,第一时间想到的解决方案就是把初始化逻辑尽量减少,但是总有一些不可避免的情况。
比如数据库初始化过程,基本每个入口都需要用到。
又比如multidex动态加载,要做到按需,维护量且不说,还有依赖关系。
换一个思路,就是把这些逻辑放到欢迎页(才明白欢迎页不仅仅是一种UI设计,更是一种程序设计,专门为这种场景诞生的)
入口这么多,那岂不是每个入口都有?而且而且,android所有的应用都基于内存回收的方式去运行,随时根据activity栈进行进行restore,所以你如果想把初始化逻辑放到欢迎页,那几乎所有的地方都得判断是否已经初始化,没有初始化就跳转欢迎页再回来。当然也可以放到Base类中,但还需要与原本的逻辑代码衔接,不得不弃用原本的onCreate函数另起一个,对原本代码的侵入性也是很强的。
这里提供一套通用的解决方案,依旧把初始化逻辑放到application中,原理是应用启动的时候,开启另外一个进程相当于一个只有欢迎页的app,初始化完毕后返回到原本的应用。
品高Link技术团队