android hot update framework! 330-page PDF, a summary of knowledge points of 100,000 words, an annual salary of 50W

We programmers are often confused that there are too many things to learn, and some of us can't find directions and are at a loss.

Many programmers are willing to say, I want to be better, but what is better is vague, and we don't know how to do it. Our lives are so short, our careers as programmers may be shorter. So we need to make full use of work, work breaks, evenings, and weekends to study. Next, let’s take a look at a learning plan provided by Tencent Classroom for senior Android architects from first-line Internet companies.

Componentization

1.1 The original intention of componentization

  • With the continuous iteration of APP version and the continuous increase of new functions, the business will become more and more complicated, and the maintenance cost will be high.
  • The degree of business coupling is high, the code becomes more and more bloated, and it is difficult for multiple people within the team to collaborate and develop.
  • When compiling the code of the Android project, the computer will be very stuck, and because of the serious coupling of the code under a single project, each code modification must be recompiled and packaged, which is very time-consuming.
  • It is convenient for unit testing and changes a single business module without focusing on other modules being affected.

1.2 What is componentization

Componentization is to divide an app into multiple Modules, as shown in the figure below. Each Module is a component (or a basic library for component dependencies). During the development process, we can debug some components separately, and the components do not need to depend on each other. , But can call each other, when the final release, all components are dependent on the main app project in the form of lib and packaged into an apk.

1.3 Advantages of componentization

  • Componentization is to separate common modules and manage them in a unified manner to improve reuse and split the page into smaller granular components. In addition to the UI implementation, the components also include the data layer and the logic layer.
  • Each project can be compiled independently, speed up the compilation, and packaged independently.
  • Modifications within each project will not affect other projects.
  • The business library project can be quickly split and integrated into other apps.
  • The business modules with frequent iterations adopt the component approach, and the research and development of business lines can not interfere with each other, improve the efficiency of collaboration, and control product quality and strengthen stability.
  • Parallel development, team members only pay attention to their own small modules, reduce coupling, and facilitate later maintenance.

2 Componentized communication

2.1 Componentized communication

Componentization does not directly depend on each other. If component A wants to call the method of component B, it will not work. Many developers give up the use of componentization because of the complicated communication between components.

There are several ways of component communication:

####### 1. Local broadcast

Local broadcast, which is LoacalBroadcastRecevier. It is more used to communicate with components specified by different systems in the same application. The advantage is that the broadcasts sent will only be broadcast in your own APP, and will not be leaked to other apps, and other apps cannot send broadcasts to their own apps. , Without being disturbed by other apps. Local broadcast is like intercom communication. It has low cost and high efficiency. However, it has the disadvantage that the two communication mechanisms are all entrusted and the system is responsible. We cannot intervene in any steps in the transmission and cannot be controlled. Generally speaking, the proportion of components is not used in the communication process. high.

2. AIDL between processes

AIDL between processes. This granularity lies in the process, and our componentized communication process is often in threads. Moreover, AIDL communication is also system-level communication. The bottom layer is based on the Binder mechanism. Although Android provides templates for us to implement, it is often difficult for users to understand and the interaction is more complicated. , It is often not applicable to the componentized communication process.

3. Anonymous memory sharing

Anonymous memory sharing. For example, with Sharedpreferences, in a multi-threaded scenario, it is often thread-unsafe. This is more to store some information with little change, such as the configuration information in the component, etc.

4. Intent Bundle delivery

Intent Bundle delivery. Including explicit and implicit transmission. Explicit transmission requires a clear package name path. Components and components often need to depend on each other. This deviates from the SOP (Separation of Concerns Principle) in componentization. If it is implicit, not only the package name path cannot Repeat, need to define a set of rules, only one package name path is wrong, and it is slightly troublesome to troubleshoot. This method is often suitable for internal transmission between components, and there are not many usage scenarios for dealing with other components outside of the component.

2.2 One of the current mainstream practices is to introduce a third party, such as the Base Module in the figure.

3 ARouter component communication framework

3.1 Introduction to ARouter

ARouter is the middleware that provides routing functions for pages and services in Alibaba's open source Android platform. It is simple and sufficient. Mainly used for component communication

        Intent intent = new Intent(mContext, XxxActivity.class);
 intent.putExtra("key","value");
 startActivity(intent);
 
 Intent intent = new Intent(mContext, XxxActivity.class);
 intent.putExtra("key","value");
 startActivityForResult(intent, 666);

The above piece of code, in Android development, the most common and commonly used function is page jump. We often need to face the need to jump from a browser or other App to a page in our App, but even if it is simple The page jumps, as time goes by, will also encounter some problems:

  1. Centralized URL management: When it comes to centralized management, it is always painful. When multiple people develop collaboratively, everyone goes to AndroidManifest.xml to define various IntentFilters and uses implicit Intents. Finally, they find that AndroidManifest.xml is full of With various Schames and various Paths, it is necessary to frequently solve problems such as Path overlap coverage, excessive activity being exported, and security risks.

  2. Poor configurability: Manifest is limited to xml format, it is troublesome to write, complicated to configure, and there are fewer things that can be customized

  3. Unable to intervene during the jump process: Jump directly through the Intent method, the developer cannot intervene during the jump process, and some aspect-oriented things are difficult to implement, such as logging in and burying points, which are very general logic, which is judged in each subpage. It is very unreasonable, after all, the activity has been instantiated

  4. Cross-modules cannot be explicitly dependent: When the App is small and large, we will split the App horizontally, split into multiple sub-modules according to the business, and completely decouple the app functions through the packaging process, so that it is convenient to deal with large-scale applications. The team collaborates with many people and does not interfere with each other's logic. At this time, it can only rely on implicit intent jumps, which is troublesome to write and difficult to control whether it succeeds or not.

In order to solve the above problems, we need a routing component that can be decoupled, simple, multi-functional, highly customizable, and supports interception logic: we chose Alibaba's ARouter, be lazy, and directly paste ARouter's Chinese introduction document:

3.2 ARouter advantages

Learn about its advantages from ARouter Github:

Supports direct parsing of standard URLs to jump, and automatically injects parameters into the target page. Supports the use of multi-module projects. Supports the addition of multiple interceptors. The custom interception sequence supports dependency injection. It can be used as a dependency injection framework. Solution) The mapping relationship is classified by group, multi-level management, on-demand initialization, support for users to specify global downgrade and partial downgrade strategy pages, interceptors, services and other components are automatically registered to the framework. Support multiple ways to configure transition animations. Support to obtain Fragment. Full support Typical applications of Kotlin and mixed editing:

Mapping from external URLs to internal pages, as well as parameter passing and parsing, cross-module page jumps, decoupling between modules to intercept the jump process, processing logic such as login and burying points

Cross-module API calls, decoupling components through inversion of control

Three, typical application scenarios

  1. Mapping from external URL to internal page, as well as parameter passing and parsing
  2. Cross module page jump, decoupling between modules
  3. Intercept the jump process, handle the logic of login and burying points
  4. Cross-module API call, decoupling between modules (registered ARouter service form, call each other through the interface)

to sum up

In fact, it is very simple to master easily, and there are two main points:

  1. Find a good set of video materials and follow the knowledge framework that Daniel has sorted out to learn.
  2. Practice more. (Video advantage is strong sense of interaction, easy to concentrate)

You don't need to be a genius, and you don't need to have a strong talent. As long as you do these two points, the probability of success in the short term is very high.

For many junior and mid-level Android engineers, if they want to improve their skills, they often grow up on their own. The learning effect of fragmented systems is inefficient, long and helpless. The screenshots of the following information are compiled by me over several months, and I am full of sincerity: it is especially suitable for Android programmers with 3-5 years of development experience to learn.

%BD%95%E9%9D%A2%E8%AF%95%E6%8B%BF%E9%AB%98%E8%96%AA%EF%BC%81.md)】。**

[External link pictures are being transferred...(img-vxeFnpZh-1614248588298)]

Guess you like

Origin blog.csdn.net/a120464/article/details/114098195