Chapter One: Life cycle and startup mode of activity
Life cycle
- OnPause says activity is stopping, Onpaus must be executed first (the activity at the top of the stack), and the new activity's onresume will be executed. OnStop indicates that the activity is about to stop (transparent will not be performed), and can do a bit of heavy-duty recycling. OnPause and onStop cannot handle too time-consuming operations, because OnPause must perform new activity after completion to resume
- OnStart and OnStop are callbacks from the perspective of whether activity is visible, and Onresume and OnPause are callbacks from the perspective of whether the activity is located in the foreground, except for this distinction, there is no other difference in actual use, to reclaim or initialize the data, You can see the situation ahead or back.
- when the activity is terminated, onsaveinstancestate is called to save the state of the current activity, which is not normally called by the system. The Onrestoreinstancestate and OnCreate methods can be used to determine if the activity has been rebuilt, and if it is rebuilt, the previously saved data can be retrieved and restored. The difference between the two is: once the onrestoreinstancestate is called, its parameter bundle must be value, and no additional judgment is required to be empty. In terms of timing,The timing of Onrestoreinstancestate calls is after OnStart.
- Some background work is not suitable to leave the four components and run in the background alone (the system will keep an empty process after the program exit to facilitate the system to start again), so that the process is easy to kill, the better way is to put the background work in the service to ensure that the process has a certain priority, so it will not be easily killed by the system
- It's often used to draw curves.
Startup mode
- When there is no activity in the stack, the system recycles the task stack.
- Standard: Normal mode. There can be multiple instances in a task stack, and each instance can belong to a different task stack. In this mode, who initiates the activity, the activity is running in the same stack as the activity that started it, for example, activity a initiates activity B (b is the standard mode), then B enters the stack where a is located
- Singletop: Stack top multiplexing mode. In this mode, if the new activity is already at the top of the stack, the activity will not be created repeatedly, and its Onnewintent method will be called back, and the current requested information can be fetched through the parameters of this method. Singletask mode will also callback this method
- There are two ways to specify the activity's startup mode. The first is specified by the manifest file, and the second is to specify the startup mode for the activity by setting the flag bit in intent. There are two of them, but others. First, priority, the second is higher than the first, when the two species at the same time, the second approach, and then the two ways in the scope of the difference, for example, the first way can not directly set the ACTIVITY flag_activity_clear_top indicator, The second method cannot specify SingleInstance mode for activity
- Implicit startup, only one intent matches the action, category, data to be an exact match, and only an exact match to successfully start the target activity. There can be multiple intent-filter in an activity, and a intent can successfully initiate the corresponding activity as long as it matches any set of Intent-filter
Chapter II: IPC Mechanisms
- IPC means inter-process communication or cross-process communication, which refers to the process of data exchange between two processes. IPC is not unique to Android, and any operating system requires a corresponding IPC mechanism.
- There is only one way to use multiple processes in Android, which is to assign the process attribute to the four components in the manifest file, but there is no other way
- There are problems with many processes, but we cannot formally do this because there are many problems with many processes. To solve this problem, the system provides a lot of cross-process communication methods, although not directly shared memory, but through cross-process communication or can achieve data interaction. There are many ways to communicate across processes, such as passing data through intent, sharing files and sharedpreferences, Binder-based message and aidl, and sockets.
- The serializable and Parcelable interfaces can complete the serialization of objects, and we need to use them when we need to transfer data through intent and binder. There are times when we need to persist objects to a storage device or to other clients through the network, which also requires serialization
- With serializable serialization, you only need this class to implement the Serializable interface and declare serialversionuid, in fact, even this serialversionuid is not necessary, do not declare this Serialversionuid can also be serialized, but this has an impact on deserialization. When deserializing, the system detects the Serialversionuid in the file to see if he is consistent with the serialversionuid of the current class, and if consistent, the version of the serialized class is the same as the version of the current class, which can be serialized successfully. If the class structure changes in a non-conventional way, such as modifying the class name, the member variable type, deserialization will fail, because the class structure has a devastating change, simply cannot restore a new class structure object from the old version of the data. Note: A static member variable belongs to a class that does not belong to the object, so it does not participate in the serialization process, followed by a member variable marked with the Transient keyword that does not participate in the serialization process
- Aidl usage Flow: First create a Services service and a AIDL interface, then create a class that inherits from the stub class in the Aidl interface and implements the abstract method in the stub (that is, the method that defines the interface). Returns the object of this class in the service's Onbinder method, and then the client can bind the Server service to establish a connection to access the remote server
- If the company project is huge, now there are 10 different business modules need to use AIDL for interprocess communication, do not need to create 10, 100 services, you can put all the aidl in the same service to manage, with binder connection pool, specific reading
The sixth chapter: Android drawable
- drawable represents a kind of abstract concept that can be drawn on canvas, it has many kinds, the most common color and picture can be a drawable. Advantage: First of all, it is simple to use, lower than the cost of custom view, second, the non-image type of drawable occupies a small space, which can reduce the size of the APK is also helpful. Drawable is commonly used as a background for view, which is generally defined by XML, and can also be used to create specific drawable, which is more complex to create.
- The interior width of the drawable can be obtained by means of getintrinsicwidth and getintrinsicheight. But not all drawable have wide, such as a picture of the formation of the drawable, its interior width is the height of the picture, but a color of the formation of the drawable, it does not have the concept of interior width and height, in addition to note that Drawable's internal width is not equal to its size, in general, drawable is no size concept, when used as the background of the view, drawable will be stretched to the same size of view
- Classification of drawable (subclass): Bitmapdrawable, Shapedrawable, statelistdrawable, levellistdrawable, Transitiondrawable, Insetdrawable, scaldrawable, clipdrawable, etc.
- The use of drawable is very simple, one is displayed as an image in the ImageView, and the other is the background of the view.
Seventh: Android animation in-depth analysis
25.Android Development Art Research note