AsyncHttpClient无法正常工作

时间:2012-06-29 11:13:04

标签: java android android-async-http

我在onCreate()中有以下计时器:

new Timer().scheduleAtFixedRate(new TimerTask(){

            public void run() {
                Log.i("EOH","timer");
                updateMarkers();
        }}, 0, 1000);

如您所见,它每秒调用函数updateMarkers()。

这是updateMarkers():

private void updateMarkers(){
        Log.i("EOH","updateMarkers()");
        Drawable drawable = this.getResources().getDrawable(R.drawable.google_maps_marker);
        final MyItemizedOverlay itemizedoverlay = new MyItemizedOverlay(drawable,mapView);

        AsyncHttpClient myClient = new AsyncHttpClient();
        final PersistentCookieStore myCookieStore = new PersistentCookieStore(context);
        myClient.setCookieStore(myCookieStore);
        RequestParams params = new RequestParams();
        params.put("sw_lat", String.valueOf(centrePoint.getLat()-(Double.valueOf(mapView.getLatitudeSpan())/2.0)));
        params.put("sw_lng", String.valueOf(centrePoint.getLat()-(Double.valueOf(mapView.getLongitudeSpan())/2.0)));
        params.put("ne_lat", String.valueOf(centrePoint.getLat()+(Double.valueOf(mapView.getLatitudeSpan())/2.0)));
        params.put("ne_lng", String.valueOf(centrePoint.getLat()+(Double.valueOf(mapView.getLongitudeSpan())/2.0)));

        myClient.post("http://www.prestocab.com/ajax/getRanks.php", params, new AsyncHttpResponseHandler() {

            public void onStart() {
                thinger.setVisibility(View.VISIBLE);
                Log.i("EOH","onStart()");
            }


            public void onSuccess(String response) {
                Log.i("EOH","xxx: "+response);
                thinger.setVisibility(View.INVISIBLE);

                try{
                    JSONArray arr=(JSONArray) new JSONTokener(response).nextValue();
                    Log.i("EOH","yyy: "+String.valueOf(arr.length()));
                }catch(JSONException e){

                }


            }


            public void onFailure(Throwable e) {
                thinger.setVisibility(View.INVISIBLE);
            }


            public void onFinish() {

            }

        });

    }

我遇到的问题是Log.i("EOH","onStart()");永远不会被调用!但是Log.i("EOH","updateMarkers()");被称为......

我做错了什么?

非常感谢,

2 个答案:

答案 0 :(得分:0)

我发现AsyncHttpClient的当前实现 - 我开始使用的第一个 - 版本1.4.3(2013-09-25)与本地Intranet主机名有一些问题。我正在使用本地网络测试我的计算机上运行的网络服务器,它正在调用onStart,但从不调用onSuccess或任何其他方法。

我的主机名是RM_UB02(没有Internet域后缀)。 Android和Chrome网络浏览器能够解析网址(http:// RM_UB02 / test / page.html),但AsyncHttpClient从未运行过。

我更改为本地Intranet IP地址(192.168.1.104)并开始工作。 我发现它可以正常使用互联网名称(http://slashdot.org),但不适用于本地网络。

答案 1 :(得分:-3)

@Override
public void onStart()
{
}

@Override
public void onFinish()
{
}

@Override
public void onSuccess()
{
}

@Override
public void onFailure()
{
}
相关问题