Basic programming and development knowledge

Source: Internet
Author: User

Basic programming and development knowledge

I. Rxjava (responsive programming library with functions: asynchronous, concise, and observer Mode)
Conclusion: Rx is a programming interface that uses the observed data stream for asynchronous programming. It combines the observer mode, iterator mode, and functional programming. It is a programming model designed to provide consistent programming interfaces for more convenient processing of asynchronous data streams.
1. the Observable sends an event notification to the Observer by subscribing to the Observer (Observer or Subscriber.
2. Create an observer and define the onNext () Action triggered by the event. At last, onCompleted () and onError () can be called only one.
3. Some trigger events will be defined when an observer is created, and these event methods will be called during subscription. Observable can use create (), just (), from () and other operators to create the event source type;
4. Subscription to subscribe (Observer) will call the methods defined by the Observer in sequence. You can also change the Observer to a custom incomplete callback, and override call () by defining the type of no return value for the Action () complete the callback you need. Here we use the closure principle.
5. thread control is switched through sched. By default, events generated and consumed are both in the same thread, and production and consumption threads are specified through subscribeOn () and observeOn, the thread can be switched multiple times, but subscribeOn () can only be switched once.
6. Transformation: The Event Sequence or object is processed and transformed into a new one, map () one-to-one transformation, flatMap () one-to-many transformation, lift () the transform is similar to the proxy mechanism to intercept and then process the event, and the compose (Transformer) transform to the Observable itself.
7. Subscriber. onStart () differs from doOnSubscribe (). Before an event occurs, the former cannot determine the thread specified by subscribe, the latter can determine that the event is consumed in the specified thread before the event occurs. Other functions are the same.
Ii. EventBus event bus/message transmission
To sum up, EventBus stores a bunch of methods in a single example. In post, it searches for methods based on parameters for reflection calls. The core architecture is implemented based on the observer mode.
1. When register is registered, register (this) traverses all the methods in the previous class, finds the method starting with onEvent, and records the event information (including method, threadMode, and eventType) encapsulate it into SubscriberMethod and add it to the List according to the priority value. Finally, all information about the method is stored in subscriptionsByEventType in the form of Map, which solves the storage problem of EventBus.
2. When post is sent, the parameter param is published. EventBus uses reflection to scan and find the parameter in its internal storage, while Map is used to store the parameter in EventBus, the key is the Class type of the parameter, and the value is the method that stores the beginning of a bunch of onevents.
3. okhttp network request framework (http-based implementation instead of secondary encapsulated request Library)

Conclusion: The Request is constructed through various key-value pairs, which can be set by builder () based on the builder mode, then, OkHttpClient converts it to Call and transmits it to RealCall for asynchronous or synchronous tasks. RealCall is a Dispatcher task queue consisting of thread pool and reverse proxy mode, in this way, non-blocking and high concurrency problems are solved, and network requests and returned results are sent through interceptor. The interceptor uses the responsibility chain design mode, and requests are sent out and down layer by layer until the response is obtained and uploaded layer by layer.

4. Binder IPC

The android IPC principles include AIDL, Intent, Messergen, and four components are implemented based on the Binder. The Binder serves as a bridge between the system service layer and the application layer,
At the application layer, the Client calls the Driver at the kernel layer and calls the Server (this is the IBinder object returned by onBind () in the service). The Server starts a thread pool to process Client call requests, after the processing is complete, the result is returned to the Driver, and the Driver is returned to the Client. The Server is thread insecure.
Benefits of Binder:
1. Use drivers to promote inter-process communication
2. improve performance through shared memory
3. The thread pool of each process allocated for the process request. Two Binder service threads started by each process by default
4. Introduce technology and cross-process object reference ing to objects in the system

5. synchronous calls between processes.

5. Handler Principle

Handler is related to the asynchronous message processing thread. After the asynchronous message processing thread is started, it enters an infinite loop body. Each cycle fetches a message from its internal message queue, then, callback the corresponding message processing function. After a message is executed, the loop continues. If the message queue is empty, the thread will block the wait. There are four roles: Handler, logoff, Message, and MessageQueue.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.