开发者

How can I change Swingworker to AsyncTask in Android?

开发者 https://www.devze.com 2023-03-17 03:06 出处:网络
How can I change Swingworker toAsyncTask in Android? My code is as follows. private void showWeather() {

How can I change Swingworker to AsyncTask in Android?

My code is as follows.

private void showWeather() {
        // TODO Auto-generated method stub
         SwingWorker worker = new SwingWorker<WeatherInfo,Object>()
         {
             public WeatherInfo doInBackground()
开发者_如何学Go             {
                 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();
    }


You should be using AsyncTask instead

0

精彩评论

暂无评论...
验证码 换一张
取 消