1

We are currently working with flavors to create differing apps with the same codebase. I've run into this scenario:

I have two Apps, App A and App B. Inside src/main, so in both flavors' scopes, I have an activity called Start_Activity. From Start_Activity, I want to move to either A_Activity or B_Activity, based on which app we're in. A_Activity and B_Activity are only in the scope of their respective flavors.

What's the best way of attempting this? I don't want to move Start_Activity into the separate flavors, since that'd defeat the point of reusing code.

Can I resolve an activity class for an Intent from ressource files or from the manifest? Or can I only create a class with same-named-constants that exists in each flavor?

Edit

I neglected to mention that I specifically don't want to use a method where the activities share the same name and only exist in the scope of their respective flavors (for example, renaming both A_Activity and B_Activity to X_Activity).

I don't want to use this because I could run into the situation where I have App C that also wants to use A_Activity. Using this method, I'd have to have the A_Activity file in both flavors for App A and App C, which is not clean enough for what I want to do.

TomQDRS
  • 875
  • 1
  • 7
  • 20

2 Answers2

1

Look here: https://stackoverflow.com/a/16746755/7325737

"If you want to have a different version of the same class in the two flavor you'll need to create it in both flavors.

src/flavor1/java/com/foo/A.java
src/flavor2/java/com/foo/A.java

And then your code in src/main/java can do

import com.foo.A

depending on the flavor selected, the right version of com.foo.A is used."

I think this should help you!

Hani
  • 104
  • 5
  • Thank you Hani! While this is definitely correct, I should've mentioned that I specifically don't want to use this method, because I also could run into the situation where I have **App C** that also wants to use `A_Activity`. Using your method, I'd have to have the `A_Activity` file in both flavors for **App A** and **App C**, which is not clean enough for me. – TomQDRS Jul 02 '19 at 14:25
1

In Start_Activity you can create the start intent via Intent.parseUri(..) which can be loaded from a config file or a string resource

k3b
  • 14,517
  • 7
  • 53
  • 85
  • How can I use a URI for activities inside my app? Do I have to declare the URI in the app's manifest? – TomQDRS Jul 02 '19 at 14:55
  • I used this method and it works! Would you mind adding an example to be more clear to other people looking for the answer? Or can I edit an example into your answer? – TomQDRS Jul 03 '19 at 11:18