2010-09-08 121 views
-5

我开发了一个应用程序,我希望将来自Class1 editText的URI发送到包含editText的另一个类。
谁能告诉我该怎么做?共享首选项

+0

这是什么都与共享偏好呢? – Falmarri 2010-09-08 07:43:04

回答

0

假设你想使用SharedPreferences转移URI,你可以试试这个:

SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); 
prefs.edit().putString("my-uri", "http://google.com/").commit(); 

并获取URI:

prefs.getString("my-uri", "default URI"); 

如果你的两个类是活动的,如果其中一个启动另一个,你应该通过URI作为一个额外的意图。

另外,请阅读FAQ并接受一些答案!

0

可以使用System.setProperty /获取属性为好。

0

你不喜欢添加putExtra的意图

这样

Intent i = new Intent(getApplicationContext(), Audit_FSD_Tab.class); 
      i.putExtra("UsrID", UsrID); 
      i.putExtra("Store", Store); 
      i.putExtra("location", location); 
      startActivityForResult(i, 0); 

现在在其他活动获得这些额外的

 Bundle UsrVal = null; 
     UsrVal = this.getIntent().getExtras(); 
    UsrID = UsrVal.getString("UserId"); 
    Store = UsrVal.getString("Store"); 
    location = UsrVal.getString("location"); 
0

尝试存储乌里在编辑文本中在第一个活动中共享首选项,然后在第二个活动的创建方法中从共享首选项中检索Uri值,并在编辑文本中显示该值。简单...