Hub*_*ert 13
作为活动中的内部类:
public final class HttpTask
extends
AsyncTask<String/* Param */, Boolean /* Progress */, String /* Result */> {
private HttpClient mHc = new DefaultHttpClient();
@Override
protected String doInBackground(String... params) {
publishProgress(true);
// Do the usual httpclient thing to get the result
return result;
}
@Override
protected void onProgressUpdate(Boolean... progress) {
// line below coupled with
// getWindow().requestFeature(Window.FEATURE_INDETERMINATE_PROGRESS)
// before setContentView
// will show the wait animation on the top-right corner
MyActivity.this.setProgressBarIndeterminateVisibility(progress[0]);
}
@Override
protected void onPostExecute(String result) {
publishProgress(false);
// Do something with result in your activity
}
}
Run Code Online (Sandbox Code Playgroud)
然后在你的活动的某个地方:
new HttpTask().execute(someParams...);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8931 次 |
| 最近记录: |