共享参数存储:
保存键值对应的数据:
保存一些持久化的数据类型:布尔,浮点,整型,长整型,字符串
getSharedPreferences()
:文件被多个应用程序访问
getPreferences()
:共享文件只是当前Activity访问
步骤:
- Call
edit()
to get aSharedPreferences.Editor
. - Add values with methods such as
putBoolean()
andputString()
. - Commit the new values with
commit()
单选测试:
<uses-library android:name="android.test.runner" />
单元测试:
登录记住用户名: