Android-Ion FutureCallBack,结果为“”
我正在开发一个应用程序,我使用koush的库: 有时它工作得很好,我得到的结果成功或用户已经存在从php文件echo成功;有时结果是一个空字符串 我不能张贴整个代码,因为它太多,但你可以要求它的一部分。 有熟悉离子的人能帮我吗Android-Ion FutureCallBack,结果为“”,android,ion,Android,Ion,我正在开发一个应用程序,我使用koush的库: 有时它工作得很好,我得到的结果成功或用户已经存在从php文件echo成功;有时结果是一个空字符串 我不能张贴整个代码,因为它太多,但你可以要求它的一部分。 有熟悉离子的人能帮我吗 public void registerNewUser(String fname, String lname, String email, String country, String aboutu, String uidenty, final Runna
public void registerNewUser(String fname, String lname, String email,
String country, String aboutu, String uidenty, final Runnable r) {
Ion.with(context,
"http://project.com/index.php")
.setBodyParameter("firstname", fname)
.setBodyParameter("lastname", lname)
.setBodyParameter("email", email)
.setBodyParameter("country", country)
.setBodyParameter("aboutu", aboutu)
.setBodyParameter("useridentification", uidenty)
.setBodyParameter("tag", "register").asString()
.setCallback(new FutureCallback<String>() {
@Override
public void onCompleted(Exception ex, String res) {
if (ex != null) {
Log.e("ion-error", ex.getMessage());
Toast.makeText(
context,
"The registration failed. Try again later.",
Toast.LENGTH_LONG).show();
} else if ("succeed".equals(res.replace("\t", " ")
.trim())) {
r.run();
} else if ("User already exists".equals(res.replace(
"\t", " ").trim())) {
Toast.makeText(
context,
"This Email is already in use. Try another one.",
Toast.LENGTH_LONG).show();
}
}
});
}
调试时是否出现异常? 尝试设置超时值
Ion.with(context,
"http://project.com/index.php")
.setBodyParameter("firstname", fname)
.setBodyParameter("lastname", lname)
.setBodyParameter("email", email)
.setBodyParameter("country", country)
.setBodyParameter("aboutu", aboutu)
.setBodyParameter("useridentification", uidenty)
.setBodyParameter("tag", "register")
.asString()
.setTimeout(20000)
.setCallback(new FutureCallback<String>() {
........................your code.......
}
可能会在发生这种情况时检查服务器日志。还可以在ion中启用详细日志,并提供详细日志。我发现只有在调试时才会发生这种情况。不要在FutureCallBack中设置断点。