共享偏好

时间:2010-09-08 07:04:16

标签: android android-activity android-intent bundle

我开发了一个应用程序,我想将Class1 editText中的URI发送到另一个包含editText的类 谁能告诉我怎么做?

6 个答案:

答案 0 :(得分:3)

SharedPreferences是错误的方法。使用每个Intent可以拥有的Bundle功能:http://developer.android.com/reference/android/content/Intent.html

在第二项活动中,您可以拨打getExtra()并在那里开始......

答案 1 :(得分: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并接受一些答案!

答案 2 :(得分:0)

您也可以使用System.setProperty / get属性。

答案 3 :(得分: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");

答案 4 :(得分:0)

尝试将Uri存储在第一个活动中共享首选项内的编辑文本中,然后在第二个活动的create方法中从共享首选项中检索Uri值,并在编辑text.simple中显示...

答案 5 :(得分:0)

可以使用共享首选项,例如

 SharedPreferences pref = getApplicationContext().getSharedPreferences("MyPref", MODE_PRIVATE); 
 Editor editor = pref.edit();
 data=pref.getString("key_name5", null);
 editText.setText(data);

您可以关注tutorial here

http://firstcode.info/android-sharedpreferences-basics/

相关问题