【问题标题】:Android - Ion FutureCallBack with result=""Android - 离子 FutureCallBack 结果=“”
【发布时间】:2014-09-03 22:08:28
【问题描述】:

我正在开发一个应用程序,我使用来自 koush 的 lib Ion:here

有时效果很好,我从 php 文件中得到“成功”或“用户已存在”的结果(回显“成功”;),有时结果是“”一个空字符串。

我不能发布整个代码,因为它太多了,但你可以要求它的一部分。 有熟悉 Ion 并且可以帮助我的人吗?

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 中启用详细日志记录并提供该功能。
  • 我发现它只在调试时发生。不要在 FutureCallBack 中设置断点。

标签: android android-ion


【解决方案1】:

您在调试时是否遇到任何异常? 尝试设置超时值。

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.......
         }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-12-19
    • 2019-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-16
    • 2015-03-05
    • 2019-05-21
    相关资源
    最近更新 更多