如何在Android中将Swingworker更改为AsyncTask?

时间:2011-07-01 09:06:58

标签: java android android-asynctask

如何在Android中将Swingworker更改为AsyncTask?

我的代码如下。

private void showWeather() {
        // TODO Auto-generated method stub
         SwingWorker worker = new SwingWorker<WeatherInfo,Object>()
         {
             public WeatherInfo doInBackground()
             {
                 YahooWeather yahooWeather = new YahooWeather();
                 return yahooWeather.getWeatherInfo();
             }
             public void done()
             {
                 try {
                      WeatherInfo wInfo = get();   // get WeatherInfo result from background thread
                      updateGUI(wInfo);
                    }
                    catch(Exception e){} 
             }
         };
         worker.execute();
    }

1 个答案:

答案 0 :(得分:1)

您应该使用AsyncTask代替