不同程序之間不允許共享SharedPreferences。其他程序訪問不了該程序的SharedPreferences。只能通過sqlite數據庫實現。
解决方案 »
- managedQuery和getContentResolver这两个方法的原理是什么
- android传字符串给PHP,可是PHP为什么解析出来是乱码
- kernel 编译问题
- Android音频系统ALSA中的asound.conf文件中解析扬声器音量的位置?
- 刚在android官网下载最新的SDK,但用SDK Manager 下载出这样的错误,Failed to fetch URL https://dl-ssl.go
- 查看设备已安装软件的命令是什么?
- 使用手机浏览器实现基站定位
- spinner的样式如何更改
- Android Studio简单登录界面 真机调试时点击登录闪退
- dex2jar初学者问题
- 用什么方法可以跑起android源码 中app目录下的 android自带的应用 比如android主界面
- 2个Activity如何操作同一个存储对象,类似于注册和修改用户注册信息功能
mBootNumEdit.setText(String.valueOf(mBootNum));
mSleepTimeEdit.setText(String.valueOf(mSleepTime));
settings.edit()
.putString(BootNum, mBootNumEdit.getText().toString())
.putString(SleepTime, mSleepTimeEdit.getText().toString())
.commit();
Log.i("mBootNumEdit",String.valueOf(mBootNum));
Log.i("mBootNumEdit",String.valueOf(mSleepTime));
存的是String
====================================================================
取得是int
private void GetSharedPreferences() {
BootNumTV=(TextView)findViewById(R.id.Bootnum);
SleepTimeTV=(TextView)findViewById(R.id.Sleeptime);
SharedPreferences settings = getSharedPreferences(SETTING_Infos, 0);
mBootNum=settings.getInt(BootNum, 1);
mSleepTime=settings.getInt("SleepTime", 1);
BootNumTV.setText(String.valueOf(mBootNum));
SleepTimeTV.setText(String.valueOf(mBootNum));
}
=====================
异常信息
E/AndroidRuntime( 1558): java.lang.RuntimeException: Unable to start activity ComponentInfo{wistron.mojo/wistron.mojo.boot.UpdateProgress}: java.lang.ClassCastException: java.lang.String
================================
至于SharedPreferences所存的值在当前应用的任何程序都可以调用只要是本应用
A extends Activity( A填写用户名,密码)
B extends Activity( B显示A中提交的用户名,密码)
没有理解什么意思Bundle类可以在intent页面跳转的时候传递数据,作用范围和数据范围:传送方、接收方 当传送方和接受方被finish()数据随之消失
在Android SDK2.0中关于SharedPreferences有这么一句话:Assign a name to your set of preferences if you want to share them with other components in the same application,
在Google I_O 的文档Inside_the_Android_Application_Framework.pdf中有关于Process,Activity,application之间 的关系图
我再试试。请问下,可以在哪里上传图片?
Parameters
name Desired preferences file. If a preferences file by this name does not exist, it will be created when you retrieve an editor (SharedPreferences.edit()) and then commit changes (Editor.commit()).
mode Operating mode. Use 0 or MODE_PRIVATE for the default operation, MODE_WORLD_READABLE and MODE_WORLD_WRITEABLE to control permissions.
Returns * Returns the single SharedPreferences instance that can be used to retrieve and modify the preference values.See Also * MODE_PRIVATE
* MODE_WORLD_READABLE
* MODE_WORLD_WRITEABLE
====================================================================
UpdateProgress 取得是int 问题已经解决,正如dongsheng_hu指出的一样,所以改用
settings.edit()
.putInt(BootNum,Integer.valueOf(mBootNumEdit.getText().toString()))
.putInt(SleepTime,Integer.valueOf(mSleepTimeEdit.getText().toString()))
.commit();
就OK了。超级汗,由于.xml文件中定义了太多的view id。结果不小心引用错了id,找了半天才找到nullpointexception异常出现的原因。谢谢大家。