开发者

Shared preference

I developed one app in that I want to send URI from Class1 editText to another class containing editText.

Can any开发者_开发百科one tell me how to do that?


SharedPreferences are the wrong way to do that. Use the Bundle feature every Intent can have: http://developer.android.com/reference/android/content/Intent.html

On the second activity you can call getExtra() and there you go...


Assuming you want to use the SharedPreferences to transfer the URI, you could try this:

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

And to retrieve the URI:

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

If your two classes are Activities, and if one of them starts the other one, you should probably pass the URI as an intent extra.

Also, read the FAQ and accept some answers!


you can use System.setProperty/get Property as well.


don't you like to add putExtra in intent

like this

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

now in other activity access these extra

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


Try to store Uri in the edit text inside shared preferences in first activity and then on create method of second activity retrieve Uri value from the shared preferences and display that in edit text.simple...


It can be possible by using Shared Preferences, for example

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

You can follow tutorial here

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜