Back to project page android-json-http.
The source code is released under:
Apache License
If you think the Android project android-json-http listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.open.jsonhttp.util; /* ww w .j av a 2 s. c om*/ import java.io.File; import com.open.jsonhttp.AsyncTask; import com.open.jsonhttp.HttpRequest; import android.os.Handler; import android.os.Message; /** * <p> * ??????????? * </p> * http://hi.baidu.com/wenfengyvn/item/79905fb737cf1077254b0904 * http://www.android-study.com/jichuzhishi/376.html * * @author yinghui.hong */ public class ThreadUtil { /** * ????????GET????? * * @param url * @param handler */ protected static AsyncTask doGet(final String url, final Handler handler) { AsyncTask task = new AsyncTask() { @Override public void run() { Message message = HttpRequest.doGet(url); if (!Thread.currentThread().isInterrupted()) { handler.sendMessage(message); System.out.println("is running"); } else { System.out.println("is interrupted"); } } }; task.start(); return task; } /** * ????????POST????????? * * @param url * @param handler * @param file * ?? * @return */ protected static AsyncTask doPost(final String url, final Handler handler, final File file) { AsyncTask task = new AsyncTask() { @Override public void run() { Message message = HttpRequest.doPost(url, file); if (!Thread.currentThread().isInterrupted()) { handler.sendMessage(message); System.out.println("is running"); } else { System.out.println("is interrupted"); } } }; task.start(); return task; } /** * ????????POST???JSON??? * * @param url * @param handler * @param requestBody * JSON? * @return */ protected static AsyncTask doPost(final String url, final Handler handler, final String requestBody) { AsyncTask task = new AsyncTask() { @Override public void run() { Message message = HttpRequest.doPost(url, requestBody); if (!Thread.currentThread().isInterrupted()) { handler.sendMessage(message); System.out.println("is running"); } else { System.out.println("is interrupted"); } } }; task.start(); return task; } }