Android multi project app structure

227 views Asked by At

I wonder what is the best way(if possible) to separate app into multiple independent parts. For example if you have 3 separate units that do different stuff, and you may have 2 different apps that combine 2/3 of this parts, how would you do it?

I'm coming from windows background, where in Visual Studio, you can have multiple independent projects under one solution, and then you can reuse them where you need it.

Can you have this in android? I know I can put things under different packages, but not sure how would do separation of resources.

Is there any difference between using Eclipse or Android studio for this purpose?

Any guidance or resource would be very helpful :)

3

There are 3 answers

0
pdegand59 On BEST ANSWER

You can build android-libraries (.aar) for different parts of your applications and bundle all the different part into a main project that simple assemble all the stuff found in the .aar into a single application.

1
Rudi Kershaw On

There is a lot to be said about sticking to the basics. Here are some broad concepts that I think could be helpful to keep in mind.

Implicit Intents

In Android you can have what are called Implicit Intents which essentially mean that you can have your app say "I need something that can do this for me", and the Android OS will look for apps which can accomplish the task for you. Using implicit intents and intent-filters you could create several separate apps to accomplish each task within the scope of your solution. That way each application could accomplish a portion of your solution and could still work independently.

Fragments

Fragments are re-usable UI components that can be plugged into your Activities willy-nilly. Create one, keep is loosely coupled, and you can re-use it throughout your app and any other apps you create later.

Good Object-Oriented Design

There is a lot to be said about simple, good object oriented design. By keeping your program logic away from your activities in separate classes (and keeping those classes highly cohesive and very loosely coupled), they can be easily re-used/recombined into other software/application.

Although the above is fairly broad. It's fair to say, just keep it simple and you should be able to re-use code in whichever new applications you need.

I hope this helps.

References:

0
C0D3LIC1OU5 On

There is a feature in Gradle (Android Studio default build system) called build flavors. It will let you set up which class/resource files a given build flavour (package) will use . You might want to take a look at that as it comes pretty close to what I think you want to do.

Here is a good tutorial. Here is the official explanation.