I have an application that communicates to server. I want my application to READ ONLY the socket's inputstream when NEW DATA is available for fetching.
Currently, I create a timer that scheduled for the reading of socket's inputstream every 20ms(polling) using SocketChannel class of java.nio.channels. This is not that good because it will end up of reading the socket even if there's no available data. And it drains the battery fast.
Is there an API for Android that will tell or send a flag to the connected client whenever a new data is available so that it is the only time I will read the inputstream?