Search code examples
androidmodular

Android Modular Programming


My Problem might not be valid. And the points I mention here might be little incorrect as I am neither perfect nor expert.

I have a shopping application and I want to start building a modular application. Like I want to add Affiliate User( the module which adds certain functionality or this will display some extra pages in an application) in the application.

A similar situation happens in the Frameworks: We add and enable the certain module and in return framework load everything as required.

for this, I want following changes like:

  1. add an entry in the NavigationView displaying "Affiliate Label".
  2. load fragments (just adding one more fragment for one more label/option from navigation view).

Let's say I have a library project that contains a Fragment and all relevant code.

How can I build the application automatically let's say just by writing "true" somewhere in the XML?

Automatically here means label is added, Intents are performed on click of label etc.

<Modules>
<enable>true/false</enable>
</Modules>

This is just the simple scenario.


Solution

  • You could do this (like everywhere when it comes to writing code) in many possible ways.

    1. The "file" way: Make a new file named something like modules.txt with key value pairs. Load the file and check whether a module is enabled or not.
    2. The "Constant" way: Make an abstract class which only contains public static final variables which describe your modules.
    3. The "package manager" way: See create Android Application plugins/extensions (apk)
    4. The "multiple" apk way: Note that this is not reccomended!

    we encourage you to develop and publish a single APK

    multiple apk support