简体   繁体   English

Android在哪里保存属性

[英]Where does Android save properties

Where does Android save properties used by getprop and setprop ? Android保存getpropsetprop使用的属性在哪里?

What happens when we use setprop to set a property? 当我们使用setprop设置属性时会发生什么? Is it written to a persist file, a temporary file, or in memory only? 它是写入持久文件,临时文件还是仅存储在内存中?

You can saved your project properties using Shared Preferences 您可以使用“共享首选项”保存项目属性

//To save settings
SharedPreferences settings = getSharedPreferences("FileName", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = settings.edit();
editor.putString("username","hello");
editor.putString("password", "123456");
editor.commit();

//To get Settings
settings.getString("username","");
settings.getString("password","");

or you can use the Application Object to save settings 或者您可以使用应用程序对象来保存设置

The files are saved on the applications data storage that is not accessible by other applications as an XML file 这些文件保存在其他应用程序无法作为XML文件访问的应用程序数据存储中

EDIT 编辑

Property system is an important feature on android. 属性系统是android的一个重要特性。 It runs as a service and manages system configurations and status. 它作为服务运行并管理系统配置和状态。 All these configurations and status are properties. 所有这些配置和状态都是属性。 A property is a key/value pair, both of which are of string type. 属性是键/值对,两者都是字符串类型。 From the sense of function, it's very similar to windows registry. 从功能的角度来看,它与Windows注册表非常相似。 Many android applications and libraries directly or indirectly relies on this feature to determine their runtime behavior. 许多Android应用程序和库直接或间接依赖于此功能来确定其运行时行为。 For example, adbd process queries property service to check if it's running in emulator. 例如,adbd进程查询属性服务以检查它是否在模拟器中运行。

How property system works The high level architecture of property system is shown as following. 属性系统如何工作属性系统的高级架构如下所示。 在此输入图像描述

Most of the values are key value pair so must be XML. 大多数值都是键值对,因此必须是XML。 More details can be found here 更多细节可以在这里找到

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM