Question

I'm having a lot of doubts and after two days of searching I still haven't found a good answer for my problem.

I have an app's project that is already in the store and this project have lots of Activities, Fragments, Services, IntentServices, Layouts, and resources (images, strings, integers, colors, styles, raws, drawables, etc...).

Now, I need to implement a new app that is almost a copy of the first one where I need only to change the background, some resources (but almost 99% stay the same), and maybe in one or two fragments I'll need to change some code (implement different logic statements).

I decided and I think it's natural to convert the all project in an library project.

I did:

1º Create a new project called framework and configured as library. Copied all code and resources (with the exception of assets folder) from the original project to here. 2º In the original project I leave only the manifest, proguard file. I change the manifest and proguard file to reference the classes of the new library.

I tested the app to see if was still working and it was Ok. Until now I did only the separation.

Now, came the problem. I need to create a solution reusable,and scalar for the library that allows me to use it in different apps.

In my original project I created a subclass of Application class that I use for global variables.

Without any others ideas, I decided the following: 1º Convert my MyApplication class in an abstract class. Also, I create an interface ApplicationInterface with some methods like isBackgroundOverlayed() or getBackgroundResource() that I use in the fragments to change the backgrounds or any other logic from the originally defined. 2º In the App's project, I created a new Application class that extends the abstract class MyApplication and implements the interface ApplicationInterface and which is declared in the Application tag in the manifest file.

Conclusion: This all works and I was able to have two app's projects with different background and other images like logos and even change some code logic. An example is in the original App when the user press one certain button, the App shows a dialog choice. In the new app when the user press the button it execute one fragment (without choice).

My concerns: I don't feel this is the best solution for the problem or best practice or good "pattern".

Do you have any ideas?

Thank you in advance!

ps: Sorry if I haven't use this forum properly. I search for an answer but I didn't found any.

Was it helpful?

Solution

I think you have achieved what you wanted, but that was a lengthy and time consuming process. One more thing I would like to mention is you should not change library projects for different applications

As said on Android developers guide :

Library projects contain shareable Android source code and resources that you can reference in Android projects. This is useful when you have common code that you want to reuse.

you can read more from here

Also you have to figure out,which lib is doing which work in case you forget what changes you have made

I would suggest you to keep a separate copy of original project and then import it into new work space in Eclipse (by checking copy project into current work space so that you have a new copy of your project) and consider changing its package name to get a new project

you can refer ans on this link to see how to change package name`

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top