Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the right way to insert an activity in another project?

I have an Android Studio project which consists of a login activity with relative style, manifest, IntentService and other stuff.

I want to insert this little project in many other apps, what is the best way to proceed ? Is Module the right way ?

The ultimate goal is still to easy maintenance, such as if one day the server should change URL, I would not have to make changes in any application that uses this login activity :-)

like image 645
marco Avatar asked Mar 30 '16 08:03

marco


1 Answers

You need to extract these components in a separate module:

A module is a discrete unit of functionality which you can compile, run, test and debug independently.

Modules contain everything that is required for their specific tasks: source code, build scripts, unit tests, deployment descriptors, and documentation. However, modules exist and are functional only in the context of a project.

Then, include that module in all projects using it.

In fact, you can create the module in an independent "library" project of its own. And add it as a dependency for all projects using it.

Going a step further, you can publish the output of an open source library project as .aar or .jar on maven central, jcenter and other public repositories. Then other people will also be able to use your module.

Some important points to remember when creating android library projects:

  1. The resources (strings, layouts, xmls, images) of a library will be merged with those of final project on build. Still your module's R class will stay under your module's package name.

  2. Some attributes from manifest file of library might be merged to that of final project (like that of <application> ). So, a library module should have a minimal manifest file, with at most, the package name.

  3. You may include an example application project inside a library module, but do not redestribute the example app project with library. It will cause trouble for someone building an application using your library.

like image 94
S.D. Avatar answered Oct 07 '22 00:10

S.D.