简体   繁体   English

AsyncHttpClient不起作用

[英]AsyncHttpClient not working

I have the following timer in onCreate(): 我在onCreate()中有以下计时器:

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

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

As you can see, it calls the function updateMarkers() every second. 如您所见,它每秒调用一次函数updateMarkers()。

Here is 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() {

            }

        });

    }

The problem I'm having is that Log.i("EOH","onStart()"); 我遇到的问题是Log.i("EOH","onStart()"); never gets called! 永远不会被叫! However Log.i("EOH","updateMarkers()"); 但是Log.i("EOH","updateMarkers()"); gets called... 被叫...

What am I doing wrong? 我究竟做错了什么?

Many thanks in advance, 提前谢谢了,

I found out that current implementation of AsyncHttpClient - the first I start using - version 1.4.3 (2013-09-25) has some problem with local intranet hostnames. 我发现当前的AsyncHttpClient实现-我开始使用的第一个-版本1.4.3(2013-09-25)对于本地Intranet主机名存在一些问题。 I was testing using a local network with the webserver running on my computer and it was calling onStart, but never calling onSuccess or any other methods. 我正在使用本地网络进行测试,该Web服务器运行在我的计算机上,并且正在调用onStart,但从未调用onSuccess或任何其他方法。

My hostname was RM_UB02 (without the Internet domain suffixes). 我的主机名是RM_UB02(不带Internet域后缀)。 Android and Chrome web browsers were able to resolve the URL (http:// RM_UB02/test/page.html), but AsyncHttpClient never worked. Android和Chrome网络浏览器能够解析URL(http:// RM_UB02 / test / page.html),但AsyncHttpClient却无法使用。

I changed to the local intranet IP address (192.168.1.104) and it started working. 我更改为本地Intranet IP地址(192.168.1.104),它开始工作。 I figured out that it was working all right for Internet names ( http://slashdot.org ), but not for local networks. 我发现它可以正常使用Internet名称( http://slashdot.org ),但不适用于本地网络。

@Override
public void onStart()
{
}

@Override
public void onFinish()
{
}

@Override
public void onSuccess()
{
}

@Override
public void onFailure()
{
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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