How to share common code ?

Put your problem here if it does not fit any of the other categories.

How to share common code ?

Postby AndreySerj » Tue Mar 11, 2008 3:43 pm

For example, I have two independent android-applications that use the same methods from some utility class. This class could contain a big amount of usefull and wide-used operations ...
I would like to have one 'analogue of common jar-file' containing such a utility class(es) to share this functional among other needy android-applications. How can I implement such an idea on Android ? What an alternative way is ?
AndreySerj
Developer
Developer
 
Posts: 31
Joined: Wed Dec 26, 2007 9:57 am
Location: Minsk

Top

Postby sxjthefirst » Thu Mar 13, 2008 12:45 pm

Put your class in a package of it's own. Say com.android.mypack.myclass;

Then import and use the class and it's exposed methods.

That is the recommended way to do it in Object Oriented design.
sxjthefirst
Developer
Developer
 
Posts: 36
Joined: Wed Mar 12, 2008 7:24 pm

Postby certron » Fri Mar 14, 2008 11:08 pm

I believe the problem is that if you are going to be just importing by the package name, the class files will be included into the deployable file in both cases, so you aren't saving any space, and if you change the code, you'll have to make sure that both versions are in sync, which means compiling and deploying both programs.

I don't know what your purpose is, but you might want to look at some of the OpenIntents projects, as they have stuff that provides data to other stuff, which might be useful for your stuff. I hope, at least.
certron
Junior Developer
Junior Developer
 
Posts: 12
Joined: Tue Jan 29, 2008 4:42 pm

Postby AndreySerj » Mon Mar 17, 2008 7:10 am

Thanks to all for your replies. My aim is to develop a shared widget library. I am using such an approach:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.               . . .
  3.  
  4.                 String name = "com/test/TestWidget";
  5.  
  6.                 DexFile dexFile = new DexFile(new File("/data/app/widgets.jar"));
  7.  
  8.                 ClassLoader cloader = getClass().getClassLoader();
  9.  
  10.                 Class<?> clazz = dexFile.loadClass(name, cloader);
  11.  
  12.                 Constructor<?>[] constructors = clazz.getDeclaredConstructors();
  13.  
  14.                 Constructor<?> constructor = constructors[0];
  15.  
  16.                 View view = (View)constructor.newInstance(context);
  17.  
  18.               . . .
  19.  
  20.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4
AndreySerj
Developer
Developer
 
Posts: 31
Joined: Wed Dec 26, 2007 9:57 am
Location: Minsk

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: MSNbot Media and 23 guests