在Android应用程序中存储全局常量的位置? [英] Where to store global constants in an Android application?

查看:691
本文介绍了在Android应用程序中存储全局常量的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我会知道在编译时存储全局常量的最佳实践是什么,这些常量可以随环境(debug,preprod,prod,release等)而改变。

在iOS中,我曾经将所有全局常量保存在一个头文件中,并使用预处理器宏对其进行更改,查看此答案: 在哪里存储全局常量在iOS应用程序中?



我应该为Android使用什么解决方案?

解决方案

在基本包文件夹中创建类常量


(或者创建一个接口而不是一个类,所以不需要每次都引用这个类,但是这是由于代码的可读性,不好的练习,但它会工作)



填充它> public static


此外,以及接口也可以声明为 abstract


I would know what is the best practice for storing global constants which can change with the environnement (debug, preprod, prod, release, etc) at compile time.

In iOS, I used to keep all global constants in a header file and change it with pre-processor macro see this answer:

Where to store global constants in an iOS application?

What solution should I use for Android ?

解决方案

Create a class constants in your base package folder.

(or create an interface instead of a class so there is no need to reference the class everytime, however this is bad practice due to code readability, but it will work)

Fill it with public static final values.

Moreover, both the class as well as the interface can also be declared as abstract.

这篇关于在Android应用程序中存储全局常量的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆