简体   繁体   English

Android Studio项目不同模块的访问常量

[英]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.

相关问题 在Android Studio中的不同模块之间共享项目属性 - Sharing project properties between different modules in Android Studio 具有不同模块的Android项目(sharedPreferences) - Android project with different modules(sharedPreferences) 现有的android studio项目模块问题 - Existing android studio project modules issue Android Studio 未在项目结构中显示模块 - Android Studio not showing modules in project structure 在一个Android Studio项目中使用多个模块 - Use multiple modules in one Android Studio project Android Studio 中的哪些配置定义了一个 android 项目的模块之间的差异 - Which configurations in Android Studio define the differences between modules of a android project (Dis-)在Android Studio项目中拥有多个模块的优势? - (Dis-) Advantage of having multiple modules in an Android Studio Project? Android Studio:多模块项目中外部JAR的链接 - Android Studio: Link of external JAR in a multi modules project Android Studio:为什么我的New项目包含2个模块 - Android Studio: Why does my New project contain 2 modules Android studio自定义项目模板,包含两个或多个模块 - Android studio custom project template with two or more Modules together
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM