Try to pass all network requests (I use it with db transactions too) through a android.os.Handler. Use Runnables (better implement your own Runnable class) to implement the actions to perform (add callbacks, logging and other logic in your Runnable class). This way you can easily register listeners in your Runnable class to do whatever sleeping or failures your are interested in.
Here is some code from my project.
The M_ClientRunnable class implements Runnable and has additional methods for registering "cancellators", failure listeners and success listeners.
class LooperThread extends Thread {
public Handler mHandler;
public LooperThread() {
super();
start();
}
public void run() {
Looper.prepare();
mHandler = new Handler() {
public void handleMessage(Message msg) {
getLogger().info(TAG, msg.toString());
}
};
Looper.loop();
}
public boolean post(M_ClientRunnable runnable) {
if(!isAlive()) {
start();
}
if (mHandler!=null) {
return mHandler.post(runnable);
} else {
return false;
}
}
};
private LooperThread looper = new LooperThread();
@Override
public boolean post(M_ClientRunnable runnable) {
return looper.post(runnable);
}