处理程序消息是空的

时间:2012-07-03 13:54:23

标签: android handler

我想知道我的代码是否有问题,因为我有两个Handler的实例,从我的眼睛看,几乎完全一样但是一个正常返回而另一个没有。在主要活动中,它们被称为如下:

工作

BingSpatialDataService bsds = new BingSpatialDataService(Constants.BingSpatialAccessId,
                                                         Constants.BingSpatialSourceName,
                                                         Constants.BingSpatialEntityTypeName,
                                                         Constants.BingSpatialQueryKey);
bsds.FindByAreaCompleted = new Handler()
{
   public void handleMessage(Message msg)
   {
      if(msg.obj != null)
      {
         // Do something with msg
      }
   }
};

bsds.FindByArea(l.Point, searchRadius, null);

不工作

FWSDataService fds = new FWSDataService();
fds.FindByTimespanCompleted = new Handler()
{
   public void handleMessage(Message msg)
   {
      if(msg.obj != null)
      {
         // Do something with msg
      }
   }
};

fds.FindByTimespan(timespan);

fdsbsds是包含处理程序代码的类

bsds

public class BingSpatialDataService {
    public Handler FindByAreaCompleted;
    public Handler FindByIDCompleted;
    public Handler FindByPropertyCompleted;

    private String _queryKey;
    private String _serviceURL;

    public BingSpatialDataService(String accessId, String dataSourceName, String entityTypeName, String queryKey){
        _queryKey = queryKey;       
        _serviceURL = "http://spatial.virtualearth.net/REST/v1/data/" + accessId + "/" + dataSourceName + "/" + entityTypeName;
    }

    /* Public Methods */

    //http://spatial.virtualearth.net/REST/v1/data/accessId/dataSourceName/entityTypeName?spatialFilter=nearby(latitude,longitude,distance)&queryoption1&queryoption2&queryoptionN&key=queryKey
    public void FindByArea(Coordinate center, double distance, QueryOption options){
        StringBuilder sb = new StringBuilder();
        sb.append(_serviceURL);

        //Add spatial filter
        sb.append("?spatialFilter=nearby(");
        sb.append(center.Latitude);
        sb.append(",");
        sb.append(center.Longitude);
        sb.append(",");
        sb.append(distance);
        sb.append(")");

        //Add Query Options
        if(options != null){
            sb.append(options.toString());
        }else{
            sb.append("&$format=json");
        }

        //Add Bing Maps Key
        sb.append("&key=");
        sb.append(_queryKey);

        //create service request
        ServiceRequest request = new ServiceRequest(sb.toString(), RequestType.GET, ContentTypes.JSON);
        QueryServiceAsyncTask service = new QueryServiceAsyncTask(FindByAreaCompleted);
        service.execute(request);
    }

    //http://spatial.virtualearth.net/REST/v1/data/accessId/dataSourceName/entityTypeName?spatialFilter=bbox(southLatitude,westLongitude,northLatitude,eastLongitude)&queryOption1&queryOption2&queryOptionN)&key=queryKey
    public void FindByArea(LocationRect boundingBox, QueryOption options){
        StringBuilder sb = new StringBuilder();
        sb.append(_serviceURL);

        //Add spatial filter
        sb.append("?spatialFilter=bbox(");
        sb.append(boundingBox.getSouth());
        sb.append(",");
        sb.append(boundingBox.getWest());
        sb.append(",");
        sb.append(boundingBox.getNorth());
        sb.append(",");
        sb.append(boundingBox.getEast());
        sb.append(")");

        //Add Query Options
        if(options != null){
            sb.append(options.toString());
        }else{
            sb.append("&$format=json");
        }

        //Add Bing Maps Key
        sb.append("&key=");
        sb.append(_queryKey);

        //create service request
        ServiceRequest request = new ServiceRequest(sb.toString(), RequestType.GET, ContentTypes.JSON);
        QueryServiceAsyncTask service = new QueryServiceAsyncTask(FindByAreaCompleted);
        service.execute(request);
    }

fds

public class FWSDataService {
    public Handler FindByTimespanCompleted;

    private String serviceURL;

    public FWSDataService()
    {
        serviceURL = "http://10.90.32.120/fws/home/getsiterecentrainfall/?regionid=1&regionid=19&";
    }

    public void FindByTimespan(int timespan)
    {
        StringBuilder sBuilder = new StringBuilder();
        sBuilder.append(serviceURL);

        // Add timespan filter
        sBuilder.append("timespan=");
        sBuilder.append(timespan);

        ServiceRequest request = new ServiceRequest(sBuilder.toString(), RequestType.GET, ContentTypes.JSON);
        QueryServiceAsyncTask service = new QueryServiceAsyncTask(this.FindByTimespanCompleted);
        service.execute(request);
    }

}

我检查了Handler的网址,该网址无效,数据也正确返回。事实上,我在其他地方使用相同的URL,它工作正常。有什么我想念的吗?

0 个答案:

没有答案