I have found that only resources get merged this way. Source files get merged into a single build path. You will need to copy your AnotherActivity.java to each flavor as you have done with Constants.java. Look to refactor your source a bit to reduce the duplication is the best you can do. You could probably accomplish this with an AbstractAnotherActivity.java in src/main/java that the others extend.
You will notice that when you select the build variant in Android Studio it will show you only the source from the selected variant in the package view.