Openatlas There is a problem, that is, the four components must be registered in the manifest file, then it will inevitably bring a problem, the plug-in components are repeatedly registered in the host. Components such as service,contentprovider do not have a good workaround at this time and can only be registered in the host. But like activity, obviously there is a solution, is to use fragment instead of activity,activity just as a fragment container, then not only in the plug-in not to register the manifest file, even the host registration problem is solved. So, the solution, yes, is a blog post that was written. Android uses fragment to create a universal page switching framework. Before reading this article, be sure to read it first.
However, the use of this page to switch the framework also poses a problem, that is, the frame is called by reflection fragment, but in the host if the direct use of reflection, will be reported java.lang.ClassNotFoundException error, We have to use the ClassLoader of the plug-in provided by Openatlas to load, and in order to support Openatlas, I have modified the framework to enable it to support Openatlas
Add two variables to the configuration class Coreconfig, control whether Openatlas is enabled, and for setting up and getting classloader, and provide static getter and setter methods
/** * Atlas supports start * /Private Static Booleanisopenatlas=false;Private StaticClassLoader Mbundleclassloader =NULL; Public Static Boolean Isopenatlas() {returnIsopenatlas;} Public Static void Setisopenatlas(BooleanIsopenatlasflag) {Isopenatlas = Isopenatlasflag;} Public StaticClassLoaderGetbundleclassloader() {returnMbundleclassloader;} Public Static void Setbundleclassloader(ClassLoader ClassLoader) {mbundleclassloader = ClassLoader;}/** * Atlas Support END * /
Modify the original core function, determine the Boolean variable in Coreconfig, whether Openatlas is enabled, is not enabled by default. If enabled, the ClassLoader is obtained through the Getbundleclassloader function, but only if you call the Setbundleclassloader function to set the ClassLoader, the return is not empty
/** * Atlas support for Start */ if (Coreconfig.isopenatlas ()) {ClassLoader Bundleclassloader = Coreconfig.getbundleclassloader (); if (Bundleclassloader==null ) {LOG.D (TAG, "Openatlas bundle ClassLoader is null!" ); return null ; } fragment = (basefragment) coreconfig.getbundleclassloader (). LoadClass (Corepage.getclazz ()). Newinstance (); else {fragment = (basefragment) class.forname (Corepage.getclazz ()). Newinstance ();} /** * Atlas Support End */
Then when called in the host, remember to turn on Openatlas support and set ClassLoader, and ClassLoader's get is through the member function of Atlas Getbundleclassloader () to get, the function needs to pass a parameter, which is the package name of the corresponding plug-in, which is the JSON of the previously generated plug-in information list Pkgname
Later development is the development of normal programs. Note, however, that the host's ingress activity must inherit the baseactivityin the page-switching framework and do not need to call Setcontentview for page setup, directly using The Openpage function opens the Fragment , and the Fragment in the plugin must inherit the basefragmentin the page switch frame, and remember that the host Call coreconfig.init (this) in application; The initialization of the framework.
Then call it in the host and remember to set ClassLoader and turn on openatlas support. Fragment configuration file page.json** is not copied to the host * *, can be read directly.
CoreConfig.setIsOpenAtlas(true);ClassLoader bundleClassLoader = Atlas.getInstance().getBundleClassLoader("com.lizhangqu.fragment");CoreConfig.setBundleClassLoader(bundleClassLoader);openPage("test", null, CoreAnim.none);
and plug-in, the framework should not be packaged in, just compile the time to provide, specific adaptation work see the previous article Android plug-in development of the Atlas plug-in adaptation
Finally, provide a sample source code
http://download.csdn.net/detail/sbsujjbcy/9031679
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Android plugin developed to solve the registration problem of the Atlas component in the host