Source:
protected void onPostExecute(String result) { String refreshToken; String accessToken; int timeToExpireSecond; try { IdentityProxy identityProxy = IdentityProxy.getInstance(); if (Constants.REQUEST_SUCCESSFUL.equals(responseCode)) { JSONObject response = new JSONObject(result); try { accessToken = response.getString(Constants.ACCESS_TOKEN); refreshToken = response.getString(Constants.REFRESH_TOKEN); timeToExpireSecond = Integer.parseInt(response.getString(Constants.EXPIRE_LABEL)); Token token = new Token(); Date date = new Date(); String currentDate = dateFormat.format(date); token.setDate(currentDate); token.setRefreshToken(refreshToken); token.setAccessToken(accessToken); token.setExpired(false); SharedPreferences mainPref = IdentityProxy.getInstance().getContext(). getSharedPreferences(Constants.APPLICATION_PACKAGE, Context.MODE_PRIVATE); Editor editor = mainPref.edit(); editor.putString(Constants.ACCESS_TOKEN, accessToken); editor.putString(Constants.REFRESH_TOKEN, refreshToken); editor.putString(USERNAME_LABEL, info.getUsername()); long expiresIN = date.getTime() + (timeToExpireSecond * 1000); Date expireDate = new Date(expiresIN); String strDate = dateFormat.format(expireDate); token.setDate(strDate); editor.putString(Constants.DATE_LABEL, strDate); editor.commit(); identityProxy.receiveAccessToken(responseCode, Constants.SUCCESS_RESPONSE, token); } catch (JSONException e) { Log.e(TAG, "Invalid JSON format." + e); } } else if (responseCode != null) { if (Constants.INTERNAL_SERVER_ERROR.equals(responseCode)) { identityProxy.receiveAccessToken(responseCode, result, null); } else { JSONObject mainObject = new JSONObject(result); String errorDescription = mainObject.getString(Constants.ERROR_DESCRIPTION_LABEL); identityProxy.receiveAccessToken(responseCode, errorDescription, null); } } } catch (JSONException e) { Log.e(TAG, "Invalid JSON." + e); } }

Target:
protected void onPostExecute(String result) { String refreshToken; String accessToken; int timeToExpireSecond; try { IdentityProxy identityProxy = IdentityProxy.getInstance(); if (Constants.REQUEST_SUCCESSFUL.equals(responseCode)) { JSONObject response = new JSONObject(result); try { accessToken = response.getString(Constants.ACCESS_TOKEN); refreshToken = response.getString(Constants.REFRESH_TOKEN); timeToExpireSecond = Integer.parseInt(response.getString(Constants.EXPIRE_LABEL)); Token token = new Token(); Date date = new Date(); String currentDate = dateFormat.format(date); token.setDate(currentDate); token.setRefreshToken(refreshToken); token.setAccessToken(accessToken); token.setExpired(false); SharedPreferences mainPref = IdentityProxy.getInstance().getContext(). getSharedPreferences(Constants.APPLICATION_PACKAGE, Context.MODE_PRIVATE); Editor editor = mainPref.edit(); editor.putString(Constants.ACCESS_TOKEN, accessToken); editor.putString(Constants.REFRESH_TOKEN, refreshToken); editor.putString(USERNAME_LABEL, info.getUsername()); long expiresIN = date.getTime() + (timeToExpireSecond * 1000); Date expireDate = new Date(expiresIN); String strDate = dateFormat.format(expireDate); token.setDate(strDate); editor.putString(Constants.DATE_LABEL, strDate); editor.commit(); identityProxy.receiveAccessToken(responseCode, Constants.SUCCESS_RESPONSE, token); } catch (JSONException e) { Log.e(TAG, "Invalid JSON format", e); } } else if (responseCode != null) { if (Constants.INTERNAL_SERVER_ERROR.equals(responseCode)) { identityProxy.receiveAccessToken(responseCode, result, null); } else { JSONObject mainObject = new JSONObject(result); String errorDescription = mainObject.getString(Constants.ERROR_DESCRIPTION_LABEL); identityProxy.receiveAccessToken(responseCode, errorDescription, null); } } } catch (JSONException e) { Log.e(TAG, "Invalid JSON", e); } }