Android knowledge points finishing (two)

"Android Advanced Advanced" study notes
second system architecture


Chapter 16: MVP mode and its practice in Android

1. The basic concept of MVP

  1. View: View layer, including interface related functions, such as Activity, Frangment, View, Adapter, etc. This layer focuses on user interaction.

  2. Presenter layer: the logical control layer, which acts as an intermediary to isolate the View layer and the Model layer. For example, receiving the network data loading request of the View layer and distributing it to the corresponding Model for processing, while monitoring the processing result of the Model layer, and finally feeding it back to the View layer, so as to refresh the interface.

  3. Model layer: encapsulates various data sources, such as remote network data, local database data, etc., and provides a simple and easy-to-use interface to the Presenter layer.

2. The difference between MVP and MVC

MVP mode:
MVP model relationship diagram

MVC mode:
MVC pattern relationship diagram

Chapter 17: MVVM mode and Android DataBinding combat

  Compared with MVP, MVVM (Model-View-ViewModel) changes the Presenter to the ViewModel, and realizes the two-way binding of View and ViewModel at the same time. Changes in the View layer will automatically cause the ViewModel to change, and the data changes in the ViewModel will also automatically refresh the View. Developers do not need to directly deal with the update operations of the View and data. The MVVM framework will complete all of this.

MVVM mode:
MVVM model relationship diagram

  At the Google I/O 2015 conference, the Android development team released the official function library Data Binding Library supported by the MVVM mode.

Chapter 18: Extension of the Observer Model: Event Bus

  The event bus is a channel for the flow of messages (events). The message transmission between different components and modules is realized through the bus, and there is no direct communication between components and modules. In short, the event bus is used to simplify the communication between components or modules in Android applications, so as to achieve the purpose of decoupling between modules.

1. Basic principles

  • Event: An ordinary POJO class (Plain Ordinary Java Object), which only contains data, does not contain operations on data. There are two types of events: ordinary events and sticky events. The characteristic of sticky events is that after the event is published, subscribers start subscribing to this type of event, then it can still receive this event, while ordinary events cannot be received .

  • Subscriber: An object that subscribes to certain types of events. Subscribers can introduce the concept of priority.

  • Publisher: The source of the event, the object that publishes a certain type of event.

  • Bus EventBus: Responsible for the storage of subscribers, events and other information, as well as the flow and distribution of events. Through the bus, subscribers and publishers are decoupled.

The overall architecture of the event bus

2. The difference with Android BroadcastReceiver and observer mode

  • Android's BroadcastReceiver is more suitable for monitoring Android system-level broadcast time, such as network status changes, power changes, etc. For business-related event changes, using BroadcastReceiver is too heavyweight.

  • The observer mode is used for simple event monitoring, but if the observer mode is used globally to solve the communication between components and modules, it may cause the problem of interface expansion. The observer mode requires developers to implement event production, distribution, and processing by themselves, and requires good design. At the same time, the observer mode does not support sticky events, and does not support features such as event priority. Of course, in terms of performance, the observer mode has higher performance than the event bus, after all, it does not need to deal with many other characteristics.

  • The event bus is very convenient to use, but it is only used when communicating between components or modules.

Chapter 19: Writing concise and standardized code

Chapter 20: Build your own technology stack based on open source projects

1. The overall architecture of the APP

  • Application layer: Focus on the realization of industry fields, such as finance, payment, map navigation, social networking, etc. It directly faces users and is the first layer of user perception of products.

  • Basic framework layer: Focus on the realization of the technical field, and provide APP public features. It is the second perception of the product by users, such as performance and stability.

2. Logging

  1. Logger
  2. LogUtils
  3. timber

3. JSON parsing

  1. gson: Google produced
  2. jackson: For the Java language, a general-purpose JSON function library
  3. Fastjson: Produced by Alibaba, which claims to be the fastest JSON library in the Java language. There is a dedicated Android version: fastjson.android
  4. LoganSquare

4. Database operation

  1. greenDAO: Lightweight and fast ORM framework, specially optimized and customized for Android.
  2. Realm: A brand new mobile database engine.

5. Network communication

  1. android-async-http
  2. OkHttp
  3. Volley: Google listing
  4. Retrofit

6. Picture caching and display

General picture cache has two levels of cache: memory cache and disk cache .

  1. BitmapFun
  2. Picasso
  3. Glide
  4. Fresco: Produced by Facebook, with three levels of cache: two levels of memory cache and one level of disk cache, which can greatly reduce the probability of OOM in APP.
  5. Android-Universal-Image-Loader

Guess you like

Origin blog.csdn.net/michael_f2008/article/details/77934473