This content originally appeared on Level Up Coding - Medium and was authored by Prachi Jamdade
In the world of software development, you never know when an unexpected bug will occur, and your software may crash due to system failures. In such cases, feature flags/feature toggling come in handy.
Feature flags will help developers to enable/disable features instantly if any feature fails to operate in the app.
Hold on ….. Prachi! What are feature flags? Let’s go through them step by step.
What are Feature Flags?
Feature flags are just variables that allow you to enable/disable some features or parts of a system dynamically. By dynamically, what I mean is that you can enable/disable them even in runtime.
For example, using this feature flag our app can show some features to the users who have logged in and hide other features of our app from users who don't have logged in.
Another example could be, suppose you are building one feature of the app. The feature is not yet fully developed. In this case, you can hide this feature from your users until it is completed using feature flags.
Or if the feature fails to operate, you can disable the flag for this feature and your app can still work without any system failures.
How to implement Feature Flags in Android?
First of all, you need to define where the feature flags will be stored. You can store them either remotely or locally. We will see how to use them both locally and remotely.
You can use a third-party feature flag management tool like Firebase Remote Config.
Adding Parameters in Firebase Remote Config:
Firebase allows us to define the key and description for each value.
Implement Feature Flag Check
Define one method to check the status of the feature flag.
Below is the implementation of how remote feature flags can be defined and used. You can extend it with additional feature flags.
Next, we can implement a local feature flag using shared preference. Shared preferences are used for local storage. You can save your data and use it anywhere required in your app.
For testing purposes, you might need to bypass the login flow and test other features of your app. In such a case, you can enable this login feature flag in debug build to simply skip or bypass the login.
Remember to enable this flag in the release build of your app.
Similarly, you can use feature flags for different purposes in different build types also.
Conclusion
Feature flags are very powerful. They make code more modular and stable. It minimizes the risk of unexpected bugs and system failures.
But always remember to clean up your feature flags if they are no longer in use or if the particular feature changes.
If you've made it so far, you can follow me on Twitter. Show some love by tapping the clap button for few times. 🙌
More from Prachi Jamdade
Data Structures and Algorithms in Real Life!
Level Up Coding
Thanks for being a part of our community! Before you go:
- 👏 Clap for the story and follow the author 👉
- 📰 View more content in the Level Up Coding publication
- 🔔 Follow us: Twitter | LinkedIn | Newsletter
- 🚀👉 Top jobs for software engineers
A complete guide to implementing Feature Flags in Android was originally published in Level Up Coding on Medium, where people are continuing the conversation by highlighting and responding to this story.
This content originally appeared on Level Up Coding - Medium and was authored by Prachi Jamdade
Prachi Jamdade | Sciencx (2022-07-22T13:30:16+00:00) A complete guide to implementing Feature Flags in Android. Retrieved from https://www.scien.cx/2022/07/22/a-complete-guide-to-implementing-feature-flags-in-android/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.