2014-09-03 55 views
0

我正在開發一個應用程序,我用lib離子從koush:here的Android - 離子FutureCallBack與結果=「」

有時它的偉大工程,我得到的結果是「成功」或「用戶已存在」從PHP文件(回聲「成功」;),有時結果是「」一個空字符串。

我不能張貼整個代碼,因爲它實在是太多了,但你可以要求它的一部分。 有沒有人誰是熟悉離子並能幫助我嗎?

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

也許在發生這種情況時檢查您的服務器日誌。還啓用詳細日誌記錄並提供。 – koush 2014-09-04 16:15:05

+0

我發現它只發生在調試時。不要在FutureCallBack中設置斷點。 – ninjaxelite 2014-09-05 17:45:01

回答

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