Reputation: 635
I was wondering how does this whole API of an application work? how is it created? I know how it works in C for example when you create a .h file but thats more like creating a library.
When you have an application that runs and does stuff and also want other apps to be able to use some of its functionally, how is it done? are you supposed to create a class called API and have all the functionally (functions) you want to export be there? and then when someone wants to use your functionally he creates this class or calls a static function?
Thanks, Tomer.
Upvotes: 0
Views: 57
Reputation: 1006724
When you have an application that runs and does stuff and also want other apps to be able to use some of its functionally, how is it done?
Usually, you export one or more of your components through an Android inter-process communications mechanism (IPC). Here, by "components" I mean activities, services, broadcast receivers, and content providers.
For example, nearly every app has one "API": an activity that has an <intent-filter>
for ACTION_MAIN
and CATEGORY_LAUNCHER
. Third party apps can start up that activity.
Similarly, you could:
bindService()
and an AIDL-defined Binder
are you supposed to create a class called API and have all the functionally (functions) you want to export be there? and then when someone wants to use your functionally he creates this class or calls a static function?
Normally, your code resides in your process, and therefore is unavailable for other apps in their process.
You are welcome to create a JAR that wraps up the Android IPC interfaces that you are exporting, then distribute that JAR and documentation for it, to make it easier for third parties to use your IPC. In this case, the JAR would not be code for your own app, but rather a separate library that wraps the client side of the IPC interfaces (e.g., the JAR calls startService()
or bindService()
).
Upvotes: 1