如何在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();
    }

最佳答案

您应该改用AsyncTask

10-08 07:13