I have a background alarm running every minute using the example posted here:
My actual alarm launches an AsyncTask (since I am doing a network transaction), that looks like this:
Socket sock = new Socket("hostname.com", 1234);
OutputStream out = sock.getOutputStream();
String data = "beth";
out.write(data.getBytes());
sock.close();
What's the easiest way to make this timeout in case the network connection is unstable? I am already checking to see if the phone is connected to wifi.
setSoTimeout looks similar to what I want to use, but it appears to be only for sockets that are receiving content. I want the connection to give up after a few seconds if it fails to connect.
In response to the first comment:
Before I was running:
new Checkin().execute();
Do I now run:
new Checkin().get(10000, TimeUnit.MILLISECONDS);
To timeout after 10 seconds? And this will stop the asynctask after 10 seconds?