Search code examples
androidandroid-activitydependency-injectionconfigurable

Android and configurable application, reusable activities


I am working on a project, which at that stage will have to be customized for different customers. Application consists of some business logic and 15 different activities for the UI. Lets assume that activity A starts B, and B starts activity C. A knows about B, B knows about C. I want to be able to swap activity B (use different layout, a bit different logic to handle user interaction), but leave A and C intact. What is the best approach to achieve that? I will have more and more different activities (serving similar purpose) for different customers, so the solution needs to handle many different configurations.

I was planning on splitting customized activities to different libraries and using DI container (RoboGuice 2.0) to inject them, depending on configuration, but it looks like i still need to put all the activities in manifest.xaml, which requires double work (editing manifest + configuring DI container).


Solution

  • A knows about B, B knows about C.

    That does not sound very wise in this case.

    I want to be able to swap activity B (use different layout, a bit different logic to handle user interaction), but leave A and C intact.

    Then put A, C, and all other common code in an Android library project. Put B and other customer-specific code in a customer-specific project that depends upon the library. Have some means for A (in the library) to determine how best to launch B (for the customer). For example, you could have all customer-specific projects advertise B with the same <intent-filter> (with a nice app-specific and otherwise obscure action string), and A can simply use an Intent that will match that filter for startActivity(). A then knows about B in a generic sense ("here's the B action") without knowing the B implementation, which would be customer-specific.

    I was planning on splitting customized activities to different libraries and using DI container (RoboGuice 2.0) to inject them

    That sounds like swatting a fly with a Buick, but perhaps you have a long history with DI.

    but it looks like i still need to put all the activities in manifest.xaml, which requires double work (editing manifest + configuring DI container)

    Drop the DI container, then.