Original address: http://www.2cto.com/kf/201403/284689.html
This article describes the "plug-in" architecture based on the class loader in the Android kernel Anatomy of "New Year's Day".
1, plug-ins can not run independently, but must run in a host program, that is, the host program to call the plug-in program.
2, plug-ins can generally be installed alone.
3. The host program can manage different plugins, including viewing the number of plugins, disabling or using a plugin.
4, the host program should ensure that the plug-in compatibility, that the new version of the host program can run older version of the plugin.
Here is a detailed look at this architecture:
1. Host Program:
New Android Project Plugindevandroid
2. Plug-in Project 1:plugin1
3, plug-in Project 2:
4.1, the interface class is generally defined in the host project, such as the Iplugindev.java in this example
4.2, plug-in projects need to apply Iplugindev, you must pass an external jar package, and the jar package is added to the plugin project's build Path in the form of a library, instead of being added as an "external" jar.
4.3, the host program wants to know which plug-ins in the system, you can define an action, in this case, the following action is used.
In this case, the host program can query the list of related plug-ins through the Queryintentactivities function of the Packagemanager class.
With the plugin 's PackageName, you can access the content of the plugin's resources. For example:?
In this code, first get the resource object of the plug-in, then get the string ID value of the Version field, and then call GetString to get the value of the variable, so the host program knows the contents of the resource in the plug-in program.
In this code, you first get the list of plugins.
Then get the plugin's PackageName, as well as the plugin's Dexpath directory.
Again, get the Dexoutputdir directory.
Libpath a library file that is generally used by C + + only.
The parameter meaning of Dexclassloader:
Dexpath: The path of the plugin apk or jar package file
Dexoutputdir: The directory where the files extracted from the target apk or jar package are stored. Because the host program only has access to the directory where the application resides.
Turn-the Android implementation process based on plugin development