Take the 2-minute tour ×

if i am using ksoap2 to call a web service, how can i store the needed preference on android?

i have the following attributes required by ksoap2:

String methodname ;
String url ;
String namespace;
String action;

i would like to have the values of these attributes stored in a sort of preference on android, so whenever the user runs the application they get loaded.

I am very new to this kind of stuff, and would appreciate your help

thank you

share|improve this question

4 Answers 4

up vote 0 down vote accepted

I'm assuming you want the properties defined in a file in your project, and load that on startup. If so.. then:

1) Create an asset/ folder in your project root.

2) Define a properties file, for example ws.properties, and save it in the asset folder. The format must be like the following:


3) Read in the properties file somewhere in your code, something like this:

Resources resources = this.getResources();
AssetManager assetManager = resources.getAssets();

try {
    InputStream inputStream = assetManager.open("ws.properties");
    Properties properties = new Properties();
} catch (IOException e) {

4) Now you can proceed to reference your settings using the properties variable, like this:

String methodName = properties.getProperty("methodname");

Of course, this could be combined with the use of SharedPreferences, like others have suggested. You could then perform steps 3 and 4 only the first time your app i started, and insert these settings into the SharedPreferences. I guess this would be the cleanest way to do it if you are going to use these settings several places in your code.

share|improve this answer
thx a lot man, that was awesome!! can i modify this ws.properties through code 2? –  shadesco Mar 21 '11 at 9:37
I don't think that is possible using the AssetManager, actually. The docs say: "This class presents a lower-level API that allows you to open and read raw files that have been bundled with the application as a simple stream of bytes." –  rogerkk Mar 21 '11 at 9:54
Maybe loading the properties file into SharedPreference and then using that would be the best option, if you both want to define the properties in a file AND need to make changes to it after install time? –  rogerkk Mar 21 '11 at 9:55

Use the SharedPreferences mechanism, it is an easy way to persist key-value pairs.

share|improve this answer

You can store it in the database or create a serializable object with all necessary attributes and save it using a objectoutputstream to sdcard

share|improve this answer
  1. Firstly Declare

    private SharedPreferences _pref; private String PREFNAME = "ThumbUpChamp";

  2. then Write in onCreate()

_pref = getSharedPreferences(PREFNAME,Context.MODE_PRIVATE);

3.and use like this

Editor _edit = _pref.edit(); _edit.putFloat("Qualify1",_wpm); _edit.commit();

share|improve this answer

Your Answer


