Correct way to develope a free and paid version of an app

112 views Asked by At

I have an application that has free features and paid features.

Let's suppose that an activity, in free version can perform operation A, operation B, and has a disclaimer that in order to unlock operation C, user must purchase the full version. This activit has also ads.

The same activity, in paid version, has the same operation A, same operation B and of course the operation C unlocked. This activity has no ads.

Now, I've read that the correct way to manage a free and a paid version of an app is to create 2 flavors, in order to have a structure similar to this one: flavors structure

where in main I put the "shared" parts of my app, and then I put the only-free parts in the "free" flavor, and the only-paid parts in "paid" flavor. But what about the activity described before? How can I share this activity (and it's functionality) between the two flavors, and showing or not the operation C and ads, depending on which version of my app is installed? I don't think (and don't see the point) that I need to put this activity in both free and paid version, since I don't want to write 2 times my code when I will add code of that activity, but, instead, share code that is present in both 2 versions.

While of course I will put the only-paid features in the paid version.

1

There are 1 answers

2
navylover On

You could do like this:

if(BuildConfig.Flavor.equals("free")) {
    //do something
}
else if(BuildConfig.Flavor.equals("paid")) {
   //do other thing
}

and press ctrl + shift + f to search the BuildConfig.java file, you will see this file structure.