Android Plugin-apkplug Framework basic structure-01

Source: Internet
Author: User

Because the framework of the development of frequent reasons have not time to write the framework of the basic architecture so that everyone foggy, now the framework has been basically stable and perfect, I took the time to write about the Apkplug framework of the basic architecture and principles, but also with you to explore the use of Apkplug framework to play the update function.

The basic architecture of a Apkplug

Apkplug is simply a container that parses and maps the APK file into bundles, which we call bundles as plugins. Such as

Each APK plugin is mapped to a Bundle object in the Apkplug frame, and the full path is org.osgi.framework.Bundle. Through this bundle we can get the basic information of the plugin (itself static property).

The basic structure of the two plugins

The plugins in Apkplug are aligned with the OSGi standard, so you can also refer to the description of bundles in the OSGi standard. However, the Apkplug framework also adds some special properties (for Android)

1. Plugin Status:

Plug-in status can be obtained via bundle.getstate ()

The 1.bundle.uninstalled plugin has not been installed (may have been uninstalled or cleaned up)

2.bundle.installed plugin has been installed (not started)

3.bundle.resolved plugin has been correctly parsed by the framework (not started)

4.bundle.starting plug-in is starting (call Bundleactivator.start (Bundlecontext context))

5.bundle.stopping plugin is stopping (calling Bundleactivator.stop (Bundlecontext context)) Plugin is running

2. A brief description of some functions of the plug-in bundle class:

Can get plug-in status

public abstract int getState ();

Launch plug-in call Bundleactivator.start (Bundlecontext context)

public abstract void Start ()

Stop plug-in call Bundleactivator.stop (Bundlecontext context)

public abstract void Stop ()

Uninstalling plugins

public abstract void Uninstall ()

Plugin.xml File property mapping, you can get the corresponding property by getting (key). You can also customize the key

Public abstract Dictionary Getheaders ()

Plug-in activation Activity, only bundleactivity can be started externally (also via getheaders (). Get ("bundle-activity")

Public String getbundleactivity ()

3. Plug-in Start and stop

The plugin's entry class is Org.osgi.framework.BundleActivator it is similar to is the first entry for plug-in startup, we can do some initialization work in this entry class.

When developing the plug-in, you need to specify the implementation-specific entry class in the Plugin.xml file, with the property "Bundle-activator"

Called when the plug-in starts

public abstract void Start (Bundlecontext context)

Called when the plug-in stops

public abstract void Stop (Bundlecontext context)

4. Plugin Context Bundlecontext

Org.osgi.framework.BundleContext is the context of the plugin obtained from Bundleactivator when the plug-in starts and stops, similar to Android.content.Context.

Android.content.Context class for Plug-ins (Apkplug specific)

Public abstract Context Getbundlecontext ();

Gets the plug-in for the specified ID Bundleid is dynamically allocated by the framework when the plug-in is installed

Public abstract Bundle Getbundle (long id);

Get all plugins take advantage of this function we will be able to get all the bundles of installed plugins. To manage plugins

Public abstract bundle[] Getbundles ();

... Bundlecontext also has a number of functions, such as the OSGi service query, logoff, monitoring and other functions, this time does not explain

At this point the Apkplug framework and the basic structure of the plug-in have been combed.

Official website

QQ Exchange Group: 132433459

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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: and provide relevant evidence. A staff member will contact you within 5 working days.