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;
}

异步任务类:

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();
    }
}
4

1 回答 1

1

最简单的方法是get()使用AsyncTask. 另一种方法是实现一个OnResultListeneronResult()AsyncTask onPostExecute(). 但是,第一个解决方案应该足够了。希望这可以帮助。

于 2012-09-01T08:58:54.650 回答