16
I know that there are several questions posted on here with the same topic and error, but none of them indicate the same problem as mine, so I decided to post my question here, hoping that someone would help me point out the cause. So I'm trying to implement the login feature in my app and here's the code:
if (tag.equalsIgnoreCase(login_tag)){
// check for login response
try {
if (json.getString(KEY_SUCCESS) != null) {
String res = json.getString(KEY_SUCCESS);
if(Integer.parseInt(res) == 1){
// user successfully logged in
// Store user details in SQLite Database
DatabaseHandler db = new DatabaseHandler(mContext);
JSONObject json_user = json.getJSONObject("user");
// Clear all previous data in database
logoutUser(mContext);
Toast.makeText(mContext, json.toString(3), Toast.LENGTH_LONG).show();
db.addUser(json_user.getString(KEY_EMAIL), json_user.getString(KEY_NAME), json.getString(KEY_UID), json.getString(KEY_AVA), json_user.getString(KEY_BDAY), json_user.getString(KEY_COUNTRY), json_user.getString(KEY_PREF), json_user.getString(KEY_SPEND));
// Launch Dashboard Screen
Intent dashboard = new Intent(mContext, DashboardActivity.class);
// Close all views before launching Dashboard
dashboard.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
mContext.startActivity(dashboard);
// Close Login Screen
((Activity) mContext).finish();
}
}
} catch (JSONException e) {
e.print