android - Saving user_id responce from JSON to sharepreferance -



android - Saving user_id responce from JSON to sharepreferance -

can 1 help me out need solution, have search on so, not success !

i want store auto generated user_id receiving server json response in share preference , 1 time again share preference other activity , send parameter server

here login activity receiving unique user id in json response when sending username , pass server

public void connect(string useremail, string userpassword) throws jsonexception, ioexception { restclient1 client = new restclient1(constants.serverpath + constants.loginmethod); client.addparam("email", useremail); client.addparam("password", userpassword); client.addheader("content-type", "application/json"); seek { string response = client.executepost(); jsonobject jsonresponse = new jsonobject(response); string jsondata = jsonresponse.getstring("code"); string jdata = jsonresponse.getstring("responsestatus"); jsdata = jdata; if (jsondata.equals("200")) { system.out.println("responsestatus =" + jdata); startactivity(new intent(loginmainactivity.this, dashboardactivity.class)); finish(); } in "responsestatus" geting "login succsesfull , user_id=1" server <**<< want store response on share preference**

my basic session manager class not build storing response in json

public class sessionmanager { // shared preferences sharedpreferences pref; // editor shared preferences editor editor; // context context _context; // shared pref mode int private_mode = 0; // sharedpref file name private static final string pref_name = "apppersonal"; // shared preferences keys private static final string key_userid = "user_id"; // public static final string key_fullname = "fullname"; // public static final string key_email = "email"; // public static final string key_dob = "dateofbirth"; // public static final string key_address = "address"; // constructor public sessionmanager(context context){ this._context = context; pref = _context.getsharedpreferences(pref_name, private_mode); editor = pref.edit(); } public void createloginsession(int user_id) { // storing id in pref editor.putint(key_userid, user_id); editor.commit(); } public hashmap<string, string> getpersonaldetails() { hashmap<string, string> userpersonal = new hashmap<string, string>(); userpersonal.put(key_fullname, pref.getstring(key_fullname, null)); userpersonal.put(key_dob, pref.getstring(key_dob, null)); userpersonal.put(key_email, pref.getstring(key_email, null)); userpersonal.put(key_address, pref.getstring(key_address, null)); // homecoming user homecoming userpersonal; // todo auto-generated method stub // homecoming null; } // clear session details public void logoutuser(){ // clearing info shared preferences editor.clear(); editor.commit(); // after logout redirect user loing activity intent = new intent(_context, loginmainactivity.class); // closing activities i.addflags(intent.flag_activity_clear_top); // add together new flag start new activity i.setflags(intent.flag_activity_new_task); // staring login activity _context.startactivity(i); } }

after getting user_id following:

sessionmanager msessionmanager = new sessionmanager(context); msessionmanager.createloginsession(user_id);

android json sharedpreferences store server

Comments

Popular posts from this blog

c# - ASP.NET MVC Sequence contains no matching element -

java - Parsing XML, skip certain tags -

rest - How to invalidate user session on inactivity in a stateless server? -