Giter Site home page Giter Site logo

anrforapplication's Introduction

ANRForApplication

主要是解决在应用初始化过程太久初次打开可能造成黑屏的问题。

当然,第一时间想到的解决方案就是把初始化逻辑尽量减少,但是总有一些不可避免的情况。

比如数据库初始化过程,基本每个入口都需要用到。

又比如multidex动态加载,要做到按需,维护量且不说,还有依赖关系。

换一个思路,就是把这些逻辑放到欢迎页(才明白欢迎页不仅仅是一种UI设计,更是一种程序设计,专门为这种场景诞生的)

入口这么多,那岂不是每个入口都有?而且而且,android所有的应用都基于内存回收的方式去运行,随时根据activity栈进行进行restore,所以你如果想把初始化逻辑放到欢迎页,那几乎所有的地方都得判断是否已经初始化,没有初始化就跳转欢迎页再回来。当然也可以放到Base类中,但还需要与原本的逻辑代码衔接,不得不弃用原本的onCreate函数另起一个,对原本代码的侵入性也是很强的。

这里提供一套通用的解决方案,依旧把初始化逻辑放到application中,原理是应用启动的时候,开启另外一个进程相当于一个只有欢迎页的app,初始化完毕后返回到原本的应用。

品高Link技术团队

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.