(Android practice summary) Implementation Summary of third-party android Components

Source: Internet
Author: User

Frontier:

During android development, you often need to create third-party packages at the component level. The following describes the types of third-party packages supported by android, their trial scope, and their advantages and disadvantages. Finally, it analyzes the component implementation methods of some big platforms in the current development process.

 1.Export jarFile to implement third-party components

1.1.Implementation process:

Select project --> right-click, menu, select Export à select java/JAR --> select class and resource file (only class file is recommended) --> select Export file path, export the JAR file.

 

1.2.Applicability:

Suitable for creating third-party components without resources.

 

Additional instructions:

Third-party components that contain resources can also be implemented, but the implementation method is cumbersome and is not a standard practice. We generally do not recommend this. If you need to implement it, you can use the following two methods:

[1] resources are stored in the JAR file of the component package. when accessing resources in the class, you can obtain the component resources.

Example: ImageIcon image = new ImageIcon (this. class. getResource ("icons/logo.gif "));

Java.net. URL imgURL = GUITest. class. getResource ("/images/Snap1.jpg ");

[2] place the resource outside the JAR file of the component package and access the resource in the component, obtain the name of the R resource in the running environment (Note that if you directly use the R class in the component project to obtain the resource, the running environment will be based on the int value of the resource, find the corresponding resource in the running project)

 

 

1.3.Advantages and disadvantages:

Advantages: the real-time process is simple and fast, and conforms to the encapsulation characteristics of third-party components.

Disadvantage: Resource encapsulation is not supported.

 

 2.Project libraryReference Method

2.1.Implementation process:

Right-click "project --" and choose "Properties"> "Android"> "Library" at the bottom right of "Properties"> "Add" to Add an existing project.

 

2.2.Applicability:

In the implementation process of a large project, resource files are set in the shared project for the project to call.

2.3.Advantages and disadvantages:

Advantages:

Support Resource Sharing

In the Library mode, the resources in the component will automatically generate the R file. In the application project, you can directly reference the resources through the R file.

Disadvantages:

It requires applications between projects and is not suitable for project encapsulation.

3.Current third-party platform component implementation method

3.1.CNZZImplementation of the mobile statistics client component:

Generate a component by using a jar file. The component does not contain resource files.

 

3.2.AdmobAdvertisement client component implementation method:

Generate components by using the jar file, and perform strong coding on the layout resources of the involved forms.

 

3.3.How to Implement the components of the micro cloud game platform:

The jar file is used to generate components, and resources are implemented through external import reference projects. (The process uses batch processing, which is complicated ).

 

4.Current component implementation method of our Platform

Resources are encapsulated into components by means of jar files, and resources are read through packages.

 

Related Article

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.