THIS QUESTION HAS MOVED TO https://softwarerecs.stackexchange.com/questions/27841/plugins-architecture-for-an-android-app
I want to implement a plugin system for an Open Source app, because it has become really large, with many features that only a few users need. Releasing different apps is not a good solution, because userA wants feature7 and feature24 whilst userB wants feature39 and feature24.
Where can I find a good example of a plugin architecture?
Here is what I would like a plugin to be able to do:
For instance, one of the plugins must add a button on a particular screen, and clicking this button increments a value in the app's database. This is not doable with Content Providers and Intents, as far as I know.
I want to avoid making the core app's code complex with tons of hooks everywhere.
The form of the plugin could be a file on the SD card, an app, or anything else.
The general rule is that either onDestroy() is called, or your process is terminated, or your code crashed.
A plug-in is a bundle that adds functionality to an application, called the host application, through some well-defined architecture for extensibility. This allows third-party developers to add functionality to an application without having access to the source code.
The "onActivityDestroyed" will get called when the app is closed, so if you can check if the app is in background when it is called (so the app is already closed) you can grep exactly the moment when the app is being closed.
Android Studio plugins extend or add functionality to the Android Studio IDE. Plugins can be written in Kotlin or Java, or a mix of both, and are created using IntelliJ IDEA and the IntelliJ Platform. It's also helpful to be familiar with Java Swing.
I have done a framework that works like Robo-guice with some of its primary IoC functions. (Cut down on boilerplate codes that load views/service etc...)
But the core of which, I believe is the solution to your problem, is the ability to load separate APK "plugin" files, that includes "res" as well as <layouts>.xml
files. The <layouts>.xml
file can be independently inflated by the classes within that APK. That is, you can load a CustomView (that inflates its own <layout>.xml
) into an originating/parent App. All this is done without the Parent App APK knowing how the UI was inflated in the plugin APK.
Example of what I mean: I have a Mapping App, the framework will dynamically scan installed APK that matches the "contract" for a "add-on function" plugin, and loads the UI specific to it onto the App's View as a floating panel.
I would say a plugin framework for Android is do-able, as Android has most if not all of the necessary built in APIs to accomplish this.
These are your friends in this area of plugin development for Android:
DexClassLoader
(ClassNotFoundException
will be a pain if you don't use the correct ClassLoader
btw)If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With