2012-09-01 51 views
0
public int postToTwitter(String msg) { 
    String url = null; 

    new ImageSender().execute(); 
    // Twitlink I have to pass in next line but it showing null 
    twitter.updateStatus(msg+" "+twitlink); 

    return 1; 
} 

的AsyncTask類返回結果:從的AsyncTask

private class ImageSender extends AsyncTask<URL, Integer, Long> { 
    private String url; 

    protected void onPreExecute() { 
     mProgressDialog = ProgressDialog.show(OutgoingHome.this, "", "Sending image...", true); 
     mProgressDialog.setCancelable(false); 
     mProgressDialog.show(); 
    } 

    protected Long doInBackground(URL... urls) {    
     long result = 0; 

     ImageUpload upload = ImageUpload.getTwitpicUploader ("8b8f5db5ca383798509af8459f968dbc",auth); 
     try { 
      twitlink = upload.upload(new File(path)); 
      result = 1; 
     } catch (Exception e) {   

     } 

     return result; 
    } 

    protected void onPostExecute(Long result) { 
     mProgressDialog.cancel(); 
    } 
} 
+0

你想要返回什麼結果? –

回答

1

最簡單的方法是使用AsyncTaskget()方法。另一種方法是執行OnResultListener並在AsyncTaskonPostExecute()內調用其onResult()方法。但是,第一個解決方案應該足夠了。希望這可以幫助。