Android plug-in development of the Openatlas plug-in startup mode with Plug-in start broadcast

Source: Internet
Author: User

So far, 6 articles have been written.

    • Openatlas first experience of Android plugin development
    • Android Plugin Development Openatlas Generate plug-in information list
    • Android plug-in Development openatlas Resource Packaging Tool patch AAPT compilation
    • Android plug-in development Openatlas plug-in adaptation
    • Android plugin developed to resolve Openatlas component registration issues in the host
    • Verification of four components and application functions in the Openatlas of Android plug-in development

This article mainly introduces several Openatlas plug-in startup methods, in the Atlasconfig class, there are several static string array

publicclass AtlasConfig {    publicstaticnew String[]{};    publicstaticnew String[]{};    publicstaticnew String[]{};}

That is, the Openatlas plug-in three ways to start,delay load delay, that is, when used to load. AUTO starts with the start of the host, and the store looks at the name and doesn't know how it's going to start. Let's see where it's referenced, in fact the entire framework refers to it in two functions, in the Optdexprocess class

/**** dexopt Operations on bundles that have been installed and installed in the store ****/    Private void Optstoredex() { for(Bundle bundle:Atlas.getInstance (). Getbundles ()) {if(! (Bundle = =NULL|| Contains (Atlasconfig.store, Bundle.getlocation ()))) {Try{((Bundleimpl) bundle). Optdexfile (); LOG.E ("Optdexprocess","Optstoredex"); }Catch(Throwable e) {if(EinstanceofDexloadexception) {Throw((RuntimeException) e); } LOG.E ("Optdexprocess","Error while dexopt >>>", e); }            }        }    }/**** dexopt Operations on all bundles that are installed in the store ***/    Private void OptStoreDex2() { for(String Bundle:AtlasConfig.STORE) {Bundle bundle2 = Atlas.getinstance (). Getbundle (bundle);if(Bundle2! =NULL) {Try{((Bundleimpl) bundle2). Optdexfile (); LOG.E ("Optdexprocess","OptStoreDex2"); }Catch(Throwable e) {if(EinstanceofDexloadexception) {Throw((RuntimeException) e); } LOG.E ("Optdexprocess","Error while dexopt >>>", e); }            }        }    }

Looking at the function seems to continue to optimize for Dex.

In an Android system, all the code for an app is inside a dex file. Dex is a jar-like storage
Archived files with Java-compiled bytecode are stored. Because the Android system uses Dalvik virtual machines, you need to
Use the Java compiler compiled class file to convert to a class file that Dalvik can execute. This requires strong
, Dex, like a jar, is an archive file, which is still a bytecode file for Java code.
When the Android system launches an application, one step is to optimize for Dex, a process that has a dedicated
Tools to handle, called dexopt. The execution of the dexopt is performed when the Dex file is loaded for the first time. This
A process generates a Odex file, optimised Dex. Executing Odex is more efficient than directly executing the DEX text
The efficiency of the components is much higher.

But, I added in the log, look at the output, still do not see its output, only with the host to start the Odex optimization, configuration of the store, also do not see the optimized log output, here aside, may be I use the wrong way, generally we use delay or auto can. We configured the previous plugins. Let test start with the host, let zxing delay load, the other several for the store (actually in effect and delay almost, but probably internal really odex optimization, but I do not see the log output), the location of the configuration, in the applictaion of our host can, Use static code blocks.

 Public  class bootapp extends atlasapp {    Static{Atlasconfig.delay =Newstring[]{"Com.lizhangqu.zxing"}; Atlasconfig.auto =Newstring[]{"Com.lizhangqu.test"}; Atlasconfig.store =Newstring[]{"Com.lizhangqu.fragment","Com.lizhangqu.component"}; }@Override     Public void onCreate() {Super. OnCreate (); }}

The following plug-in starts the log output. Plug-ins launched with the host

Delay-loaded plug-in will only be loaded if it is started.


Another important issue is that if the plugin is started with the host, we need to know if the plug-in was installed successfully. The page jumps after the installation is successful. Plug-ins only need to be installed once, after the installation can be started directly. Here Openatlas provides a broadcast that broadcasts the message when the plug-in installation is complete. We can register the broadcast.

 Public  class bootactivity extends Activity {    PrivateBundlesinstallbroadcastreceiver Atlasbroadcast;Private  class bundlesinstallbroadcastreceiver extends broadcastreceiver {         Private Bundlesinstallbroadcastreceiver() {        }@Override         Public void OnReceive(context context, Intent Intent) {Try{StartActivity (NewIntent (bootactivity. This, Mainactivity.class)); Bootactivity. This. Finish (); LOG.E ("TAG","Bundlesinstallbroadcastreceiver,the bundle has install"); }Catch(Exception e) {            }        }    }@Override     Public void onCreate(Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate); Setcontentview (R.layout.activity_boot);if("false". Equals (System.getproperty ("Bundles_installed","false"))) { This. Atlasbroadcast =NewBundlesinstallbroadcastreceiver (); Registerreceiver ( This. Atlasbroadcast,NewIntentfilter (platformconfigure.action_broadcast_bundles_installed)); }Else{StartActivity (NewIntent (bootactivity. This, Mainactivity.class)); Bootactivity. This. Finish (); }    }}

In this way, you can monitor the installation of the plug-in, the broadcast only when the installation of the plug-in will be broadcast, after the successful installation will not be broadcast again, the use of the time to pay attention to the better.

Source code, do not preach csdn, on GitHub, interested in clone down to see just fine.

    • Https://github.com/lizhangqu/OpenAtlasDemo

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Android plug-in development of the Openatlas plug-in startup mode with Plug-in start broadcast

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.