2014-01-24 33 views
4

工作,我有这样的AsyncTask:AsyncTask.doInBackground没有得到要求2.3,在4.0+

public static void login(final String email, final String password, 
      final String token, final SocketHandler handler) { 
     execute(new AsyncTask<Void, Void, Void>() { 

      @Override 
      protected Void doInBackground(final Void... params) { 
       Log.d("ACEPTAR", "DOINBACKGROUND"); 
       String url = handler.servidor.getUrl(); 
       url += "/login-usuario"; 
       String str; 
       try { 
        str = postResponseFromServer(url, "mail", email, "pass", 
          password, "tipo", "1", "token", token); 
        Log.d("ACEPTAR", str); 
        final CustomJSONObject object = new CustomJSONObject(str); 
        final CustomJSONObject object2 = new CustomJSONObject(); 
        object2.put("datos", object); 
        final CustomJSONArray array = new CustomJSONArray(); 
        array.put(object2); 
        handler.on("resultado-login", array); 
       } catch (final Exception ex) { 
        ex.printStackTrace(); 
        handler.on("error-login", new CustomJSONArray()); 
       } 
       return null; 
      } 
     }); 
    } 

    @SuppressLint("InlinedApi") 
    private static void execute(final AsyncTask<Void, Void, Void> task) { 
     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { 
      task.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR); 
     } else { 
      task.execute(); 
     } 
    } 

我尝试做它在3G,总是工作。然后我连接到Wi-Fi。 AsyncTask在4.0+上被调用,但不在2.3.7-中。

我错过了什么吗?

+0

从您发布的代码中,调用方法'doInBackground()'并不依赖于您连接到wifi或移动数据。你可能想澄清你的问题 –

+0

我知道,这就是让我生气的原因 – razielsarafan

+0

它总是可重复的吗?我的意思是,每次尝试通过WiFi都会失败?您是否尝试过使用其他应用程序的WiFi,例如网络浏览器?您是否尝试过使用多种设备来查看它们是否发生在所有设备上? – nKn

回答

0

尝试创建一个单独的线程,并在那里做你的东西,用Activity.runInUiThread()发布你的结果。看看有没有什么问题。如果没有问题,那可能是因为一些AsyncTask错误。