views:

141

answers:

1

If I needed to build an android SDK that other developers can integrate into their android apps, is jarring my SDK the only way to go about it? As far as I have learnt, jarring has the following considerations:

  1. If your app uses a layout, then you have to create it programmatically. Since jar files cant carry any resources.
  2. The jar will needs to be placed in the lib/assets folder and added to the build path (in Eclipse) -- Learnt here: http://stackoverflow.com/questions/2716879/android-invoke-activity-from-within-jar
  3. The main app will have to create an Intent object and specify the package and class name in the jar to start the activity.

Any one have other ideas of going about any of the above steps?

Thanks George

+1  A: 

Creating a JAR is, in my opinion, a very bad decision. Android has specific features just for the kind of thing you're looking for. If your JAR:

  • provides some sort of (structured) data to be used in other applications, use a ContentProvider;
  • does some backround processing and makes that processing's results available to other applications, use a Service;
  • provides an Activity that gets some input from the user (or shows some information about something), eventually processes it and returns it to the calling Activity, just create that Activity and any application will be able to start your Activity as long as it's installed on the phone.

If you use one of the three solutions above, third party apps will be able to probe for whether your application is installed and, if not, prompt the user to install it. Only if your application does not fall into one of the three bullet points mentioned above should you use a JAR. Otherwise, using a ContentProvider, Service or Activity provides:

  • More standardized interaction between components
  • Better maintainability -- if you update your SDK you won't have to call everyone who uses it and tell them to upgrade.
  • No duplication -- if you were to provide a JAR and multiple applications that use it would be installed on a device, multiple copies of the JAR would be present on that device, thus using more memory than it has to. If you provide one of the three components mentioned above, one copy will satisfy all applications that need to use it.

Again, these components are specifically designed and provided by the Android OS for creating such SDKs. Please, only use a JAR if you really, really have to. Otherwise, provide a standardized ContentProvider, Service or Activity and document the way it's supposed to be used (i.e. how to use/query/integrate it).

Felix
Great! Thanks for the clarification!
Ron
You are very much welcome. Remember that if you consider this answer to fully answer the question you can click the tick that appears to the left of the answer. This will mark the question as answered and will give you and me reputation points and your accept rate will increase. This is the way Stackoverflow works and if you want to have your questions answered in the future you'll want a good accept rate. I'm telling you all this because I see you're new here. Have fun! :)
Felix
Thanks! Clicked it!
Ron