android 的属性文件
Properties file for android
我正在开发一个需要连接到远程服务器的 android 应用程序。很多类(实际上是activity)需要连接到同一个服务器,但是通过不同的RESTful web服务。不是在每个 类 中硬编码服务器地址(或 http url),是否有任何选项可以选择具有可以指示的轻型属性文件(xml,如果可能)这样的信息(所以如果 url/ip 改变,我只需要修改这个文件而不是整个源代码)以及我如何管理这个文件?仅供参考:我使用 httpclient (http://loopj.com/android-async-http/)。
您可以为此使用 SharedPreferences 接口。请参阅 Android SharedPreferences 文档以了解它。
来自 Android 文档:
The SharedPreferences class provides a general framework that allows
you to save and retrieve persistent key-value pairs of primitive data
types. You can use SharedPreferences to save any primitive data:
booleans, floats, ints, longs, and strings. This data will persist
across user sessions (even if your application is killed).
您可以关注 How to use SharedPreferences in Android to store, fetch and edit values and sharedpreferences tutorial 以获取有关如何使用它的示例。
我正在开发一个需要连接到远程服务器的 android 应用程序。很多类(实际上是activity)需要连接到同一个服务器,但是通过不同的RESTful web服务。不是在每个 类 中硬编码服务器地址(或 http url),是否有任何选项可以选择具有可以指示的轻型属性文件(xml,如果可能)这样的信息(所以如果 url/ip 改变,我只需要修改这个文件而不是整个源代码)以及我如何管理这个文件?仅供参考:我使用 httpclient (http://loopj.com/android-async-http/)。
您可以为此使用 SharedPreferences 接口。请参阅 Android SharedPreferences 文档以了解它。
来自 Android 文档:
The SharedPreferences class provides a general framework that allows you to save and retrieve persistent key-value pairs of primitive data types. You can use SharedPreferences to save any primitive data: booleans, floats, ints, longs, and strings. This data will persist across user sessions (even if your application is killed).
您可以关注 How to use SharedPreferences in Android to store, fetch and edit values and sharedpreferences tutorial 以获取有关如何使用它的示例。