开发者

Shared Preference problem in android app

开发者 https://www.devze.com 2023-03-26 08:10 出处:网络
in my app the first activity is a sign in page. In the edit boxes i am typing the user name and password. Those values are been move to an api and in return i am getting the userid from the server as

in my app the first activity is a sign in page. In the edit boxes i am typing the user name and password. Those values are been move to an api and in return i am getting the userid from the server as an xml file.

I am parsing the xml file and storing the value in shared preferrence as follows

SharedPreferences.Editor IdEditor = Id.edit();
IdEditor.putString("useridValue", chap.getid());
IdEditor.comm开发者_开发技巧it();

And in the next time when the user opens the app i want to check whether it is already signed i or not. How to check this using the value stored in Shared preference


is your Id class extending SharedPreferences ?

maybe

String userId = Id.getString("useridValue");

If your preference is stored in the default preference then you can

SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);

String userId = prefs.getString("useridValue");

on a side note you shouldn't really use a capital I on the IdEditor variable it should probably be idEditor


Check whether this entry already exist in shared preference, using:

id.containskey("useridvalue")
0

精彩评论

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