Source:
public void authenticateUser(final String username, final String password, final String url) { RestApi restApi = RestServiceBuilder.createService(RestApi.class, username, password); Call<Session> call = restApi.getSession(); call.enqueue(new Callback<Session>() { @Override public void onResponse(Call<Session> call, Response<Session> response) { mLogger.d(response.body().toString()); if (response.isSuccessful()) { Session session = response.body(); if (session.isAuthenticated()) { if (authorizationManager.isDBCleaningRequired(username, url)) { mOpenMRS.deleteDatabase(OpenMRSSQLiteOpenHelper.DATABASE_NAME); OpenMRS.getInstance() .getContentResolver() .delete(OpenMRSFormsProviderAPI.FormsColumns.CONTENT_URI, null, null); OpenMRS.getInstance() .getContentResolver() .delete(OpenMRSInstanceProviderAPI.InstanceColumns.CONTENT_URI, null, null); setData(session.getSessionId(), url, username, password); } else if (authorizationManager.isUserNameOrServerEmpty()) { setData(session.getSessionId(), url, username, password); } else { mOpenMRS.setSessionToken(session.getSessionId()); } new VisitApi().getVisitType(new GetVisitTypeCallbackListener() { @Override public void onGetVisitTypeResponse(VisitType visitType) { OpenMRS.getInstance().setVisitTypeUUID(visitType.getUuid()); } @Override public void onResponse() { System.out.println("TEST"); } @Override public void onErrorResponse() { ToastUtil.error("Failed to fetch visit type"); } }); UserManager userManager = new UserManager(); userManager.getUserInformation( UserHelper.createUserInformationListener(username, userManager)); loginView.userAuthenticated(); loginView.finishLoginActivity(); } else { loginView.sendIntentBroadcast(ApplicationConstants.CustomIntentActions.ACTION_AUTH_FAILED_BROADCAST); } } else { ToastUtil.error(response.message()); } } @Override public void onFailure(Call<Session> call, Throwable t) { ToastUtil.error(t.getMessage()); } }); }

Target:
public void authenticateUser(final String username, final String password, final String url) { RestApi restApi = RestServiceBuilder.createService(RestApi.class, username, password); Call<Session> call = restApi.getSession(); call.enqueue(new Callback<Session>() { @Override public void onResponse(Call<Session> call, Response<Session> response) { mLogger.d(response.body().toString()); if (response.isSuccessful()) { Session session = response.body(); if (session.isAuthenticated()) { if (authorizationManager.isDBCleaningRequired(username, url)) { mOpenMRS.deleteDatabase(OpenMRSSQLiteOpenHelper.DATABASE_NAME); OpenMRS.getInstance() .getContentResolver() .delete(OpenMRSFormsProviderAPI.FormsColumns.CONTENT_URI, null, null); OpenMRS.getInstance() .getContentResolver() .delete(OpenMRSInstanceProviderAPI.InstanceColumns.CONTENT_URI, null, null); setData(session.getSessionId(), url, username, password); } else if (authorizationManager.isUserNameOrServerEmpty()) { setData(session.getSessionId(), url, username, password); } else { mOpenMRS.setSessionToken(session.getSessionId()); } new VisitApi().getVisitType(new GetVisitTypeCallbackListener() { @Override public void onGetVisitTypeResponse(VisitType visitType) { OpenMRS.getInstance().setVisitTypeUUID(visitType.getUuid()); } @Override public void onResponse() @Override public void onErrorResponse() { ToastUtil.error("Failed to fetch visit type"); } }); UserManager userManager = new UserManager(); userManager.getUserInformation( UserHelper.createUserInformationListener(username, userManager)); loginView.userAuthenticated(); loginView.finishLoginActivity(); } else { loginView.sendIntentBroadcast(ApplicationConstants.CustomIntentActions.ACTION_AUTH_FAILED_BROADCAST); } } else { ToastUtil.error(response.message()); } } @Override public void onFailure(Call<Session> call, Throwable t) { ToastUtil.error(t.getMessage()); } }); }