Introduction and simple use of simplecommand framework (I)

Introduction:

Simplecommand is a lightweight framework. The framework is small and easy to understand. The main functions that can be realized by using this framework are the rapid integration of network requests, image requests, file operations and other time-consuming operations. For the network diagram picture request, the okhttp implementation is used internally

Usage scenario:

This framework is not suitable for scenarios with a large number of requests in a short time. It is more suitable for concurrent execution of 4 ~ 6 asynchronous requests

Introduction to project catalogue:

In the entire project directory of simplecommand, there are three important modules: app, sample and simplecommand

simplecommand:

This is the most important dependent module. All core functions are completed in this module. It mainly includes the following core classes:

Command: this class is the parent class of all command executors. It contains three main core methods: startc. This method will start the commandservice service and execute the time-consuming operation in the sub thread. Executec calls back to the method in the commandservice. Generally, the time-consuming operation is placed in this method to execute notifulistenersc and notify all resultlisteners

app:

The app module is mainly used for demonstration. The simplecommand module is dependent on the module dependency. Then customize the networkcommand implementation to request network data and display it to the UI interface

sample:

Is a relatively complete case demonstration module. The network request function is realized by adding the simplecommand.aar package. Please continue to read the specific usage!

Use steps: the following steps take the network request function as the demo

1 create a new LIBS folder in the new app module, and copy simplecommand.aar in LIBS of sample to this LIBS folder

2. Add the following statement to the Android block in build.gregle of your new app module:

3 add the following dependencies in the dependencies of build.gradle of APP module:

4. Create a new humourcommand (the class name can be taken arbitrarily according to the business) and integrate the networkcommand class. The specific code is as follows:

5 after the humourcommand is created, it can be used in mainactivity. Start by implementing a button click event btnclick:

The following is a brief description: appresultreceiver is a request result receiver. When we call the xxxcommand.start method, we need to pass in an appresultreceiver. After the request result is returned, the corresponding methods of listener in appresultreceiver will be called: onresultsuccess, onresultfailed, etc

Framework GitHub address: simplecommand framework

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>