【发布时间】:2017-07-15 00:56:57
【问题描述】:
我在尝试执行此代码时遇到了一些麻烦:
@Override
public void loginProcessGoogle(User googleUser) {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(Constants.BASE_URL)
.callbackExecutor(Executors.newSingleThreadExecutor())
.addConverterFactory(GsonConverterFactory.create())
.build();
RequestInterface requestInterface = retrofit.create(RequestInterface.class);
User user = new User();
String email = googleUser.getEmail() == null ? "" : googleUser.getEmail();
String name = googleUser.getName();
String googleId = googleUser.getProvider_id();
user.setEmail(email);
user.setName(name);
user.setProvider_id(googleId);
user.setProvider_name(User.provider_name_google);
ServerRequest request = new ServerRequest();
request.setUser(user);
Call<ServerResponse> response = requestInterface.socialAuthenticate(request);
response.enqueue(new Callback<ServerResponse>() {
@Override
public void onResponse(Call<ServerResponse> call, retrofit2.Response<ServerResponse> response) {
ServerResponse resp = response.body();
Snackbar.make(getView(), resp.getMessage(), Snackbar.LENGTH_LONG).show();
if(resp.getResult().equals(Constants.SUCCESS)){
SharedPreferences.Editor editor = pref.edit();
editor.putBoolean(Constants.IS_LOGGED_IN,true);
editor.putString(Constants.EMAIL,resp.getUser().getEmail());
editor.putString(Constants.NAME,resp.getUser().getName());
editor.putString(Constants.ID,resp.getUser().getId());
editor.apply();
goToProfile();
}
progress.setVisibility(View.INVISIBLE);
}
@Override
public void onFailure(Call<ServerResponse> call, Throwable t) {
progress.setVisibility(View.INVISIBLE);
Log.d(Constants.TAG,"failed");
Snackbar.make(getView(), t.getLocalizedMessage(), Snackbar.LENGTH_LONG).show();
}
});
String testString= "Hello";
}
当我调试此代码时,我在 user.setEmail(email); 中放置了一个断点,当我尝试放置一个onResponse 方法中的断点,它立即转到底部的字符串变量(testString) 在底部的字符串变量之前首先进入 response.enqueue 的最佳方法是什么,例如在 ServerResponse resp = response.body(); 中? p>
【问题讨论】:
标签: java android response retrofit2