简体   繁体   中英

Android - Ion FutureCallBack with result=“”

I am developing an App and I use the lib Ion from koush: here

Sometimes it works great and I get the result "succeed" or "User already exists" from the php file(echo "succeed";) and sometimes the result is "" an empty string.

I cant post the whole code because it is too much but you can ask for parts of it. Is there someone who is familiar with Ion and could help me?

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();
                    }
                }
            });
}

Are you getting any exception while debugging? Try to set Timeout value.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM