【android基础】android preferences
来源:互联网 发布:acr软件下载 编辑:程序博客网 时间:2024/04/25 10:21
Preferences是一种应用程序内部轻量级的数据存储方案。
通过Context对象的getSharedPreferences方法获得的对象可以被同一应用程序下其他组件共享,而使用Activity对象的getPreferences方法获得的对象只能被调用该方法所在的Activity使用。
activity_preferences.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" > <EditText android:id="@+id/edit" android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="textNoSuggestions"/></RelativeLayout>
PreferencesActivity.java
package com.example.android.sample4;import android.os.Bundle;import android.app.Activity;import android.view.Menu;import android.widget.EditText;import android.content.SharedPreferences;public class PreferencesActivity extends Activity {EditText editText;SharedPreferences sp;public final String EDIT_TEXT_KEY="EDIT_TEXT"; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_preferences); editText = (EditText)this.findViewById(R.id.edit); sp = getPreferences(MODE_PRIVATE); setPreferences(); String result = sp.getString(EDIT_TEXT_KEY, null); if(result != null) { editText.setText(result); } } public void setPreferences() { SharedPreferences.Editor editor = sp.edit(); editor.putString(EDIT_TEXT_KEY, "test preferences"); editor.commit(); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_preferences, menu); return true; } }
- 【android基础】android preferences
- Android Preferences
- android Preferences
- Android Preferences!
- Android中跨包访问Preferences
- Android之Preferences
- Android中跨包访问Preferences
- Android中跨包访问Preferences
- Delphi Android Preferences配置
- Android Shared Preferences 安全性
- android Preferences Headers错误
- Preferences Android数据存储
- android preferences使用
- Android:数据存取之Preferences
- Android数据存取之Preferences
- Android数据存取之Preferences
- 话说android系统之preferences
- 7.Android Preferences的使用
- MFC COMBOX使用
- NS3安装过程
- setsockopt函数的用法
- 详解CSS选择器、优先级与匹配原理
- timus 1005 stone pile
- 【android基础】android preferences
- YCbCr 转 RGB 保存成JPEG文件
- 最好的shell入门教程
- centos wget
- centOS install mysql
- DM6446开发攻略——u-boot-1.3.4移植(1)
- 控件布局通用解决方案
- linux之udev
- [jtable]多个源码实例