英文:
How to make a single Android activity in the manifest but use one of two implementations when launched?
问题
我的Android应用程序今天在清单中声明了一个主要活动,但设计团队希望构建一个在外观和功能上都非常不同的替代活动。我们希望基于功能标志执行A-B测试,以便一些用户在启动时看到旧活动,而一些用户在启动时看到新活动,我们可以远程控制这一点。我们已经有能力远程控制功能标志,值已经保存在SharedPreferences中。
在Android清单中保持单一活动,然后在显示任何内容之前选择两种不同实现的最佳方法是什么?
英文:
My Android app has one main activity today declared in the manifest but the design team wants to build a replacement that is very different in both look and function. We want to perform A-B testing based on a feature flag so some users see the old activity at launch and some see the new activity at launch and we can control this remotely. We already have ability to remotely control the feature flags today already; the value is saved in SharedPreferences.
What is the best way to keep a single activity in the Android manifest and then have it choose one of two different implementations before anything is displayed?
答案1
得分: 3
对于基于XML的应用程序,我在其中一个应用程序中实施的方法之一是创建了两个片段,并根据标志,在启动时简单地导航到所需的片段(Jetpack Navigation库可以使片段事务变得简单)。由于每个UI都将有其自己的独立实现,代码将更加清晰,如果应用程序基于MVVM架构,您还可以共享视图模型以根据您的需求共享业务逻辑。
类似地,在Jetpack Compose中,根据标志导航到可组合部分将是相当简单的。视图模型的工作方式与基于XML的应用程序相同。
英文:
For XML based apps, one of the method that I implemented in one of my app was that I created two fragments and based on the flag, I simply navigated to the required fragment on startup (Jetpack Navigation library can make fragment transactions simple). Since each UI will have its own separate implementation, code will be much cleaner and if the app is based on MVVM architecture, you can also share the view models to share the business logic depending upon your requirements.
Similarly, In Jetpack Compose, it would be a fairly simple to navigate to the composable based on the flag. View Models will work the same as in XML based apps.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论