Simple use of Android componentized arouter

Arouter is an Android routing framework open source by Alibaba. The GitHub address is: https://github.com/alibaba/ARouter

As for the many benefits of arouter, I won't introduce it. Here we mainly explain the simple use of arouter under the project component

Paste the project directory first:

The project is divided into four modules: basic component app, basic service (including routing service) basecommonlibrary module, business module libraryone and business module librarytwo;

Add the following code to the gradle files of the four modules:

The specific version of the dependent package can be selected by yourself.

The next step is to explain how arouter plays the role of routing in these modules.

The first is a page defined in the app module. The layout is very simple, so no code is pasted. The effect is as follows;

The code of activity part is as follows:

The click event responds to the two activities in this module (APP) and the activities in libraryone and librarytwo respectively. The first one is used to test the activty started in forresult mode.

Next is a screenshot of the activity layout in libraryone:

The activity code is as follows:

Two jumps have also been tested. They jump to the activity in the main module and the activity in librarytwo respectively. The layout and code in librarytwo are similar to those in libraryone. We won't continue to post them here. The source code of this project will be provided in the attachment. Welcome to download. The public jump class encapsulated in the basecommonlibrary module needs to be posted here. All modules jump through the routing public class in the module. The complete code is as follows:

This class mainly provides jump methods of several classes and information printing methods after jump failure. The next step is to test whether the jump can be executed normally. Please build your own code or download the demo source code to see the execution effect.

Next, let's talk about interceptors, taking the activity in libraryone as an example

We add the above annotation on the activity, where the value of extras can be used as the type of judgment. See the interceptor code for details

In the interceptor, you can judge whether it is the type to be intercepted according to the extra attribute. If interception is required, execute the oninterrupt method of callback and indicate the interception reason. You can extract the interception reason information in the route jump and print it.

Of course, other functions in arouter will not be introduced one by one. You can study them by yourself, with the source code download address: arouterdemo_ jb51.rar

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
分享
二维码
< <上一篇
下一篇>>