7

I have set an Alarm when app goes background which working fine, but inside the service I have api which is calling every 5 minutes interval for sending location to server, after app goes in background, service works continue but due network my api is not called and getting socckettimeOutException though network is available.

halfer
  • 19,824
  • 17
  • 99
  • 186
Nitesh Rathod
  • 368
  • 3
  • 15

2 Answers2

0

SocketTimeoutException happens when socket read or accept times out. eg: Reading bytes from socket input stream. Network may be available but you are not receiving data on the socket, so after the amount of time passing and not receiving any data, this exception is thrown.

you can set socket timeout value using socket.setSoTimeout(0) for no timeout.

Bardya Momeni
  • 337
  • 4
  • 13
  • 1
    I think you did not understand my question clearly. Let me explain in brief. When my application goes in background at that time only network not available when i back and open my app again it works fine. it does not throw socketTimeOutException. basically, what i am doing is, i am getting lat, long every minute and sending over to server every 2 minute. I have used alarmReceiver for that and it is working fine service does not get killed. hope you understand now this. – Nitesh Rathod Jul 05 '17 at 12:26
0

We can handle it by defining a socket timeout(make more timeouts) and later handle it by using a try catch block..

    serverSocket.setSoTimeout(10000); //set the socket timeout in milliseconds
Sujai
  • 208
  • 2
  • 6