php - Android login can't proceed to another procedure -
i'm trying build basic android login via json parser. here code:
package com.muzaffar.spycare.activity; import android.app.progressdialog; import android.content.intent; import android.os.asynctask; import android.os.bundle; import android.support.v7.app.appcompatactivity; import android.util.log; import android.view.view; import android.widget.button; import android.widget.edittext; import android.widget.toast; import com.muzaffar.spycare.app.jsonparser; import com.muzaffar.spycare.app.sessionmanager; import com.muzaffar.spycare.app.util; import com.muzaffar.spycare.r; import org.json.jsonexception; import org.json.jsonobject; import java.util.hashmap; import java.util.regex.pattern; import static com.muzaffar.spycare.app.constant.base_url_login; import static com.muzaffar.spycare.app.constant.login_success_message; /** * created oligococo on 11/2/2016. */ public class login_activity extends appcompatactivity { //declaration private edittext app_email,app_password,app_imei; private button app_login; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_login); // session manager final sessionmanager session = new sessionmanager(getapplicationcontext()); // check if user logged in or not if (session.isloggedin()) { // user logged in. take him main activity intent intent = new intent(login_activity.this, main_activity.class); startactivity(intent); finish(); } // initialization app_email = (edittext) findviewbyid(r.id.app_email); app_password = (edittext) findviewbyid(r.id.app_password); app_imei = (edittext) findviewbyid(r.id.app_imei); app_login = (button) findviewbyid(r.id.app_login); app_login.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { attemptlogin attemptlogin= new attemptlogin(); attemptlogin.execute(app_email.gettext().tostring(),app_password.gettext().tostring()); } }); } public void clicktoregisterpage(view v) { intent intent = new intent(login_activity.this, register_activity.class); startactivity(intent); } /*validate email*/ private boolean isemailcorrect(string email) { pattern pattern = pattern.compile( "[a-za-z0-9\\+\\.\\_\\%\\-\\+]{1,256}" + "\\@" + "[a-za-z0-9][a-za-z0-9\\-]{0,64}" + "(" + "\\." + "[a-za-z0-9][a-za-z0-9\\-]{0,25}" + ")+" ); return pattern.matcher(email).matches(); } /*eof validate email*/ /*process login*/ class attemptlogin extends asynctask<string, string, jsonobject> { jsonparser jsonparser = new jsonparser(); private progressdialog pdialog; @override protected void onpreexecute() { pdialog = new progressdialog(login_activity.this); pdialog.setmessage("attempting login..."); pdialog.setindeterminate(false); pdialog.setcancelable(true); pdialog.show(); } @override protected jsonobject doinbackground(string... args) { try { hashmap<string, string> params = new hashmap<>(); params.put("email", args[0]); params.put("password", args[1]); log.d("request", "starting"); jsonobject json = jsonparser.makehttprequest( base_url_login, "post", params); if (json != null) { log.d("json result", json.tostring()); return json; } } catch (exception e) { e.printstacktrace(); } return null; } protected void onpostexecute(jsonobject result) { try { if (pdialog != null && pdialog.isshowing()) { pdialog.dismiss(); } if (result != null) { string getmessage = result.getstring("message"); if (getmessage == login_success_message) { toast.maketext(getapplicationcontext(), getmessage, toast.length_long).show(); toast.maketext(getapplicationcontext(), result.getstring("user_id"), toast.length_long).show(); final sessionmanager session = new sessionmanager(getapplicationcontext()); final util setuserid = new util(getapplicationcontext()); //save user_id setuserid.savetopref("user_id", result.getstring("user_id")); //set logged status session.setlogin(true); //go terms intent intent = new intent(getapplicationcontext(), terms_activity.class); startactivity(intent); } else { toast.maketext(getapplicationcontext(), getmessage, toast.length_long).show(); } } else { toast.maketext(getapplicationcontext(), "unable retrieve data server", toast.length_long).show(); } } catch (jsonexception e) { e.printstacktrace(); } } } /*eof process login*/ }
however, can't identify problem on section:
if (result != null) { string getmessage = result.getstring("message"); if (getmessage == login_success_message) { toast.maketext(getapplicationcontext(), getmessage, toast.length_long).show(); toast.maketext(getapplicationcontext(), result.getstring("user_id"), toast.length_long).show(); final sessionmanager session = new sessionmanager(getapplicationcontext()); final util setuserid = new util(getapplicationcontext()); //save user_id setuserid.savetopref("user_id", result.getstring("user_id")); //set logged status session.setlogin(true); //go terms intent intent = new intent(getapplicationcontext(), terms_activity.class); startactivity(intent); } else { toast.maketext(getapplicationcontext(), getmessage, toast.length_long).show(); }
when login success, managed invoke:
toast.maketext(getapplicationcontext(), getmessage, toast.length_long).show();
while other code shown below ignored , not running:
toast.maketext(getapplicationcontext(), result.getstring("user_id"), toast.length_long).show(); final sessionmanager session = new sessionmanager(getapplicationcontext()); final util setuserid = new util(getapplicationcontext()); //save user_id setuserid.savetopref("user_id", result.getstring("user_id")); //set logged status session.setlogin(true); //go terms intent intent = new intent(getapplicationcontext(), terms_activity.class); startactivity(intent);
what issue receive no error etc., stuck @ login page , not able move terms.class..only first toast message shown..your appreciated...
Comments
Post a Comment