I have seen applications with add-on modules on market - these modules add-up some new functionality. What would be t开发者_如何学Che best way to do that ?
I cannot think of a descent and neat way to do that.
There are many ways. The most common is to just install another application and access it via Intents. It's definitely worth looking at Open Intents. If you are really adventurous, you can even load custom plugins with DexClassLoader.
IMHO the only way to cleanly implement this is to use Android's build-in extensibility, namely by using Intents and/or BroadcastReceivers. This is the way Android apps are supposed to communicate with each other, but it may work perfectly also for your own app by creating a main version which is extensible through Intents by your "plug-ins" which can be downloaded separately from the market.
The things you need to learn about and look for on the web to implement such functionality are
- Intents: Learn how you can use intents to pass data from one app to another or to invoke certain functionality on other apps.
- BroadcastReceiver: For listening to certain events broadcasted by your app in your "plug-ins"
- ContentProvider: The content provider is used to provide an abstraction over your data and allows your "plug-ins" to access your app data easily and nicely decoupled through Content URIs.
- Intent Filters: These are used to tell the system which kind of actions/Intents my specific Activity is able to accept. You will need them as a way for invoking your plug-ins (by broadcasting an Intent with the given action/category) as well as for providing a space in your menus where "compatible" Intents may hook in automatically.
I hope I was able to provide you some of the topics you need to know about. I'm sure that once you get a deeper understanding on these, you will get a much clearer picture on how to realize such a modular app.
精彩评论