Android - Ion FutureCallBack with result =“”

时间:2014-09-03 22:08:28

标签: android ion

我正在开发一个App,我使用来自ko​​ush的lib Ion:here

有时它很有效,我得到了结果"成功"或者"用户已经存在"来自php文件(echo" success&#34 ;;),有时结果是""一个空字符串。

我无法发布整个代码,因为它太多但你可以要求它的一部分。 是否有人熟悉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();
                    }
                }
            });
}

1 个答案:

答案 0 :(得分:0)

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

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