[英]Access constant in different modules of Android Studio project
I have a wearOS application combined with a mobile app in Android Studio.我在 Android Studio 中有一个wearOS 应用程序与一个移动应用程序相结合。 I communicate between those two with listeners who listen on certain paths and behave diffently dependent on the messages they recieve.
我在这两者之间与听众交流,他们在某些路径上收听,并根据他们收到的消息表现出不同的行为。
I had to define the meaning of the messages in each module and thereby violated the DRY-principle.我必须在每个模块中定义消息的含义,从而违反了 DRY 原则。 Is there a way to store a constant so that both modules can access it in their code and/or manifest?
有没有办法存储一个常量,以便两个模块都可以在它们的代码和/或清单中访问它?
I would suggest creating a new module for the shared code and add it as a dependency for your mobile and wear modules.我建议为共享代码创建一个新模块,并将其添加为您的移动和穿戴模块的依赖项。
Yes, it's a little bit of overhead for just a few constants.是的,这只是一些常数的一点点开销。 But it helps keep things organized.
但它有助于使事情井井有条。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.