I wrote simple application, for my Galaxy SII, for permanent connection with remote server. Ones for 5 second it sends and receives data. While application is working nobody can't call to me. Network answers him - interlocutor is unavailable. The same happend me when I use mail client like K-9. It doesn't matter I use GPRS or 3G connection.
What is a main rule (if is it?) to construct internet application to avoid this problem (I mean problem with ordinary incomming phone connection)?
My ordinary code for sending data (in remote service) is like this:
While (condition)
{
try {
Thread.sleep(500);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
out.write(data + "\n");
out.flush();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
Regards, Artik
First, if you want to wait for 5 seconds you should use Thread.sleep(5000);
not Thread.sleep(500);
which is half a second.
Second, consider sending your data to the server using Timer
instead of Thread.sleep()
and while(condition)
After modifying your code with the above suggestions, try to test from the emulator
and simulate a phone call.