【发布时间】:2014-02-20 08:57:59
【问题描述】:
我正在尝试访问在不同应用程序中创建的共享首选项文件。我遵循了一些教程,但没有用。这是我的情况:
App1 (com.example.remoteservice)
SharedPreferences configuracion2;
configuracion2 = getSharedPreferences("telo", Context.MODE_WORLD_READABLE);
Editor editor = configuracion2.edit();
editor.putFloat("x21", Float.parseFloat(x21.getText().toString()));
editor.commit();
App2 (com.example.grafica)
Context con = createPackageContext("com.example.remoteservice", MODE_WORLD_WRITEABLE);
SharedPreferences pref = con.getSharedPreferences(
"telo",MODE_WORLD_READABLE);
ancho = pref.getFloat("x21", 0);
Log.i("smash", "ancho" + String.valueOf(ancho));
并返回 0,因为不存在“telo”。为什么??
谢谢
【问题讨论】:
-
和我的代码一样...ç
标签: java android preferences