In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces the Android cold start time-consuming optimization method is what the relevant knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that everyone after reading this Android cold start time-consuming optimization method is what the article will have a harvest, let's take a look.
1, background
Recently developed a new App, the preliminary construction period is tight, and the work is relatively extensive. After launching, it is found that the startup time of App is relatively long, reaching 3 seconds.
The start-up has a white screen, and the experience is not good. This can only be optimized in the later stage, which is best considered in the early development.
2. Survey 2.1 ways to launch in Android
1. Cold start: if there is no application process in the background when App starts, the system will re-create a process to assign to the application. This startup method is called cold start.
2. Hot start: if the application process exists in the background when App starts, then the system will directly use the existing process.
From the meaning of the two start-up modes, we can see that cold start is more time-consuming, hot start is generally faster, what we need to do is cold start optimization.
2.2, cold start process
We are generally unable to optimize the system creation application process time. This is a simple process for system creation.
What we can optimize is
1,Application
2,SplashActivity
3,MainActivity
2.3, start time
1, by command
Adb shell am start-W [packageName] / [packageName.MainActivity] at this time, if the launched activity does not have export:true set in Manifest, it may not be opened by command. You need to set this.
2. Bury it yourself.
From the above startup process, we can know that when Android starts cold, the system needs to create a process first, and then create Application. We can start to bury the process in the attachBaseContext method of Application.
/ * count the time consumed by cold start at each point in time * / public class StartLogHelper {private static final String TAG = "StartLogHelper"; private static long startTime; / * set the start time, temporarily put it to the startup time, and put it in the attachBaseContext method of Application * @ param start * / public static void setStart (long start) {startTime = start } / * application initialization time, put at the end of Application's onCreate method * / public static void getApplicationTime () {long end = System.currentTimeMillis (); DebugLog.e (TAG, "= getApplicationTime==" + (end-startTime));} / * Welcome page initialization time * / public static void getWelcomeTime () {long end = System.currentTimeMillis () DebugLog.e (TAG, "= getWelcomeTime==" + (end-startTime));} / * * Main page initialization time * / public static void getMainTime () {long end = System.currentTimeMillis (); DebugLog.e (TAG, "= getMainTime==" + (end-startTime));}
3, in the logcat log of studio
Enter the package name of the application in the logcat log
Then you can see the time of each stage.
3, scheme
From the investigation of the principle of cold start, we can find out what we want to optimize.
1. Cold start-up white screen phenomenon
During the cold start, we find that there will be a white screen, first a white screen will appear, and then the UI of the welcome page will appear, which has something to do with the background windowBackground of the system settings.
Solution:
Set a custom theme property on the Welcome page
SplashActivity's manifest file sets the android:theme= "@ style/SplashScreenTheme" SplashScreenTheme attribute definition @ drawable/bg_splash bg_splash definition where the picture of bg_show is the same as the initial picture of the welcome page, so that the style of starting the white screen is the same as that of the welcome page, giving people the feeling that there is no white screen. 2. Startup time optimization
We can tell from the start-up time above
1it takes time to initialize the three-party sdk in the Magi Application onCreate
Public class AppConfigHelper {public void setAppConfig (Application application) {addSyncTask (application); addAsyncTask (application); TaskConfigManager.getInstance () .startInit ();} private void addSyncTask (Application application) {TaskConfigManager.getInstance () .addTask (new ZMLTask ("oneLogin") {@ Override public void run () {JVerifyHelper.init (application);}})) }} put together the ones that need to be executed synchronously in Application
Can be executed asynchronously and put together.
2. Home page time-consuming method
When we get to the home page, we spend less time than the user sees the data. This is because the home page loads more data. We load 7 Fragment on the home page and request more than 10 interfaces at the same time.
1. Load the home page lazily to ensure that only about 3 App startup APIs are requested.
2, the home page UI optimization, while showing that the ui after the execution of the following logic processing
3. The logic of the home page is not important to delay loading, such as request for upgrade pop-up window.
This is the end of the article on "what is the time-consuming optimization method of Android cold start?" Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "what is the time-consuming optimization method of Android cold start". If you want to learn more knowledge, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.