What is the correct way to insert activity into another project?

I have an Android Studio project which consists of input activity with relative style , manifest , IntentService and other things.

I want to insert this small project into many other applications, what is the best way to continue? Is the module correct?

The final goal, as before, is simple maintenance, for example, if one day the server needs to change the URL, I will not need to make any changes to any application using this login activity :-)

+5
source share
2 answers

You need to extract these components in a separate module :

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

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

Then include this module in all the projects he uses.

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

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

Some important points to keep in mind when creating Android library projects:

  • Resources (strings, layouts, xmls, images) of the library will be combined with the resources of the final project during assembly. However, your R class will remain under the name of your module.

  • Some attributes from the library manifest file can be combined with the attribute of the final project (for example, for <application> ). Thus, the library module must have a minimal manifest file, in which, at most, is the name of the package.

  • You can include the sample application project in the library module, but do not redo the sample application project using the library. This will cause problems for someone who is building an application using your library.

+6
source

I think you need to export the source project first:

File → Export

Then go to your new project and import the original. Remember to change the setContentView () method to indicate your original action (the one you imported)

and finally, do not forget about your intention! if you have any questions let me know and I will create a detailed answer for you, but I think that you will be fine!

0
source

Source: https://habr.com/ru/post/1246049/


All Articles