0

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();
                    }
                }
            });
}
ninjaxelite
  • 1,139
  • 2
  • 20
  • 43
  • Maybe check your server logs when that happens. Also enable verbose logging in ion and provide that as well. – koush Sep 04 '14 at 16:15
  • I found out that it only happens when debugging. Do not set the breakpoint in the FutureCallBack. – ninjaxelite Sep 05 '14 at 17:45

1 Answers1

0

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.......
         }
Meenaxi
  • 567
  • 5
  • 17