开发者

how to store wsdl preferences on android?

开发者 https://www.devze.com 2023-02-18 12:17 出处:网络
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:

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 store开发者_StackOverflow中文版d 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


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:

methodname=yourMethodNameHere
url=http://your.url.here
namespace=your_namespace_here
action=your_action_here

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();
    properties.load(inputStream);
} catch (IOException e) {
    e.printStackTrace();
}

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.


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


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


  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();

0

精彩评论

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

关注公众号