@Override protected JSONObject doInBackground(String... args) { UserFunctions userFunction = new UserFunctions(); JSONObject json = userFunction.loginUser(email, password); return json; }
@Override protected void onPostExecute(JSONObject json) { try { if (json.getString(KEY_SUCCESS) != null) { String res = json.getString(KEY_SUCCESS); if (Integer.parseInt(res) == 1) { pDialog.setMessage("Loading User Space"); pDialog.setTitle("Getting Data"); DatabaseHandler db = new DatabaseHandler(getApplicationContext()); JSONObject json_user = json.getJSONObject("user"); /** Clear all previous data in SQlite database. */ UserFunctions logout = new UserFunctions(); logout.logoutUser(getApplicationContext()); db.addUser( json_user.getString(KEY_FIRSTNAME), json_user.getString(KEY_LASTNAME), json_user.getString(KEY_EMAIL), json_user.getString(KEY_USERNAME), json_user.getString(KEY_UID), json_user.getString(KEY_CREATED_AT)); /** If JSON array details are stored in SQlite it launches the User Panel. */ Intent upanel = new Intent(getApplicationContext(), Main.class); upanel.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); pDialog.dismiss(); startActivity(upanel); /** Close Login Screen */ finish(); } else { pDialog.dismiss(); loginErrorMsg.setText("Incorrect username/password"); } } } catch (JSONException e) { e.printStackTrace(); } }