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.
Asked
Active
Viewed 646 times
7
-
1Did you ever solve this? I am getting the same issue – George Oct 16 '17 at 23:29
-
i have this issue too – Radesh Aug 01 '18 at 10:24
-
I also have this issue. Any news on how to fix it ? – matdev Mar 30 '22 at 07:10
2 Answers
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
-
1I 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