android - Strange: Intent not working after Shared Preferences Code -
i have strange problem. intent not working after shared preferences code. if write same intent before shared preferences code, working. below code...
check fetchdata() method...
login_activity
public class login_activity extends appcompatactivity implements view.onclicklistener { // widgets private spinner spnr_login_type; private edittext edt_login_id, edt_pwd; private button btn_login, btn_regi; private progressdialog progressdialog; // variables private string url = "login.php"; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_login); // checking user login or not if (preferences.getpreferences(getapplicationcontext()).contains(preferences.key_user_name)) { intent myintent = new intent(login_activity.this, home_activity.class); startactivity(myintent); finish(); } find_view_by_id(); registerclicklisteners(); progressdialog = new progressdialog(this); progressdialog.setindeterminate(true); } private void find_view_by_id() { spnr_login_type = (spinner) findviewbyid(r.id.spnr_login_type); edt_login_id = (edittext) findviewbyid(r.id.edt_login_id); edt_pwd = (edittext) findviewbyid(r.id.edt_pwd); btn_login = (button) findviewbyid(r.id.btn_login); btn_regi = (button) findviewbyid(r.id.btn_regi); } private void registerclicklisteners() { btn_login.setonclicklistener(this); btn_regi.setonclicklistener(this); } @override public void onclick(view view) { switch (view.getid()) { case r.id.btn_login: if (commom_methods.isnetworkavailable(getapplicationcontext())) { fetchdata(); } else { toast.maketext(login_activity.this, "please, coonect internet!!", toast.length_short).show(); } break; case r.id.btn_regi: intent myintent = new intent(login_activity.this, regi_activity.class); startactivity(myintent); break; } } private void fetchdata() { stringrequest stringreq = new stringrequest(request.method.post, constants.base_url + url, new response.listener<string>() { @override public void onresponse(string response) { log.e("resqq:", response); progressdialog.dismiss(); if (response != null) { try { jsonobject jo = new jsonobject(response); if (jo.has("success")) { jsonobject joobj = jo.getjsonobject("user"); // storing shared preferences preferences.writestring(getapplicationcontext(), preferences.key_sl_id, joobj.getstring("sl_id")); preferences.writestring(getapplicationcontext(), preferences.key_tution_center_sl, joobj.getstring("tution_center_sl")); preferences.writestring(getapplicationcontext(), preferences.key_batch_sl, joobj.getstring("batch_sl")); preferences.writestring(getapplicationcontext(), preferences.key_batch_grup_sl, joobj.getstring("batch_grup_sl")); preferences.writestring(getapplicationcontext(), preferences.key_co_sl, joobj.getstring("co_sl")); preferences.writestring(getapplicationcontext(), preferences.key_drange_sl, joobj.getstring("drange_sl")); preferences.writestring(getapplicationcontext(), preferences.key_reg_no, joobj.getstring("reg_no")); preferences.writestring(getapplicationcontext(), preferences.key_user_name, joobj.getstring("name")); preferences.writestring(getapplicationcontext(), preferences.key_user_email, joobj.getstring("email")); preferences.writestring(getapplicationcontext(), preferences.key_user_mob, joobj.getstring("mobile_no")); intent myintent = new intent(login_activity.this, home_activity.class); startactivity(myintent); finish(); } else { toast.maketext(getapplicationcontext(), jo.getstring("error_msg"), toast.length_long).show(); } } catch (jsonexception e) { e.printstacktrace(); } } else { toast.maketext(login_activity.this, "server error! server sent empty data!! try again later.", toast.length_long).show(); } } }, new response.errorlistener() { @override public void onerrorresponse(volleyerror error) { progressdialog.dismiss(); toast.maketext(getapplicationcontext(), "error:" + error.getmessage(), toast.length_long).show(); } }) { @override protected map<string, string> getparams() { map<string, string> params = new hashmap<string, string>(); params.put("type", spnr_login_type.getselecteditem().tostring().tolowercase()); params.put("reg_no", edt_login_id.gettext().tostring()); params.put("password", edt_pwd.gettext().tostring()); return params; } }; requestqueue queue = volley.newrequestqueue(this); queue.add(stringreq); progressdialog = new progressdialog(this); progressdialog.setmessage("fetching details!"); progressdialog.show(); //progressdialog.show(new contextthemewrapper(this, r.style.dialogcustom), "fetching details!", ""); } }
below response...
{ "success": true, "user": { "sl_id": "1", "reg_no": "21711101", "name": "akash bharadwaj n", "photo": "", "email": "", "type": "student" }, "api_key": "apikey here" }
if (preferences.getpreferences(getapplicationcontext()).contains(preferences.key_user_name))
must returning false check boolean value
Comments
Post a Comment