![](/img/trans.png)
[英]How do I reference my JSON onResponse in my postexecute method?
[英]How do I pass data with intent in onResponse method
我想将变量“点”传递给另一个活动。 当我尝试在onRensponse方法中执行此操作时,getExtrasString会返回null。 如果我尝试在调用UserSingIn的onClick方法中执行此操作,则变量“ points”为空。 有没有一种方法可以有意地在onResponse中传递它或等待onClick直到获得此数据?
private void userSingIn(){
String cardId = editcard.getText().toString().trim();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(APIUrl.DETAILS_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
APIService service = retrofit.create(APIService.class);
final User user = new User();
user.setCardId(cardId);
Call<Result> call = service.loginUser(
user.getCardId()
);
call.enqueue(new Callback<Result>() {
@Override
public void onResponse(Call<Result> call, Response<Result> response) {
Toast.makeText(getApplicationContext(), response.body().getPoints(), Toast.LENGTH_LONG).show();
userpass = response.body().getPassword();
points = response.body().getPoints();
}
@Override
public void onFailure(Call<Result> call, Throwable t) {
Toast.makeText(getApplicationContext(), t.getMessage(), Toast.LENGTH_LONG).show();
}
});
}
我想到了。 创建上下文变量并将其分配给onCreate
Context context; context = this.
然后像这样创建意图
Intent i = new Intent(context, MainMenuActivity.class);
我建议使用调试器,在意图上放置值的代码上放置断点,并检查它是否实际上具有具有变量“ points”值的String。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.