Hello, welcome to my column. This is a series of articles about Flutter. Starting with a simple introduction to Flutter, this article will take you step by step into the world of Flutter. You’d better have some mobile development experience, if not don’t worry, leave me a comment at the bottom of my column and I’ll do my best to answer it.

In my last column, I showed you how to implement a fully customizable PageView indicator with Flutter. In this column, I will teach you how to make interface jump in Flutter

In Android, we use Intent to jump from interface to interface, and startActivityForResult to handle the callback after the jump. In iOS, we use Pages to jump to Pages.

Boot mode

To accurately measure the startup time of APP, we first need to understand the entire startup process of APP. The startup process can generally be divided into the following three categories:

Iqiyi Android client startup optimization and analysis

As can be seen from the figure above, during the startup process, the Cold mode has the most things to do in the life cycle and the longest startup time. Therefore, we measure the startup time of the APP by Cold startup. During startup, how do you determine which life cycles affect startup speed?

The boot process

As we know, the startup and running of APP is the process of creating process and component objects in Linux system and processing component messages in UI thread.

Startup process diagram:

The startup process of App can be divided into three stages:

3.1 Creating a Process

When the APP starts, if the current APP process does not exist, a new process will be created. After the App main process is started, if a component is started and the android: Process property is set for the component, the process running by the component does not exist and a new process will be created.

Note that if multiple processes are included in the initialized component during startup, multiple processes will be created and the BindApplication operation will be repeated multiple times

3.2 Creating a UI thread and Handler

After the process is created, it executes the ActivityThread entry function via reflection, creates a Handler, prepares mainLooper in the current thread, and receives messages from the component in the Handler.

  • LAUNCH_ACTIVITY: Launches the Activity
  • RESUME_ACTIVITY, restore the Activity
  • BIND_APPLICATION, start the app
  • BIND_SERVICE,Service creation, onBind
  • LOW_MEMORY, out of memory, reclaim daemon

SMainThreadHandler processes a large number of messages. This section only lists the operations that may be performed during the startup phase. These operations are run on the MainThread and are obstructed for startup.

The Activity lifecycle needs to be executed during the startup phase. However, for Service creation, Trim_memory callback, broadcast reception, and other operations, the operation time needs to be taken into consideration.

3.3 Activity running and drawing

The first two processes, the creation process and UI thread and Handler, are determined by the system and the APP developer has no control over their execution time. In this stage, the execution of BindApplication and the Acitivity life cycle can be customized by the developer.

After onResume, the Activity executes to ViewRootImpl and performs two performTraversals. In the second traversal, the Activity performs performDraw and tells the RenderThread to draw.

From the three stages of startup, we can see that the length of startup time is determined by the amount of time spent doing things in the main thread. Therefore, our optimization work mainly focuses on identifying time-consuming work in the main thread and making reasonable optimization. On An Android phone, the system resources are limited. Too many asynchronous threads will preempt the CPU, resulting in an increase in the interval between the execution time slices of the main thread. Similarly, memory consumption status, GC frequency, also affects startup time

At the end

I also summarized most of the interview questions and answers involved in the Internet company Android programmer interview, and organized into a document, as well as the system advanced learning video materials, free to share with you. (including Java application, APP in the Android development framework of knowledge, senior UI, all-around performance tuning, the NDK development, audio and video technology, artificial intelligence technology, cross-platform technology such as technical data), hope to be able to help you review before the interview, and find a good job, also save you search for information on the Internet to learn.

Collection method:Pay attention to + like + click my Tencent document for free!