Efficient data loading caching on Android

I implemented a queue service in Android that will change states based on queue events and Wi-Fi / data.

I am queuing transactions to a remote URL. If the device has a data or Wi-Fi connection, it will iterate over the queue and send the data to the URL until the queue is empty or a disconnect event occurs.

I can enter my application, turn on airplane mode, generate data, turn off airplane mode and conduct a transaction. No slowdown, even with thousands of transactions. (I tried to make it out a little)

Enter: low reception! My application slows down a lot when 3G reception is low. (Yes, the entire download comes from the ui thread.) It seems that the reason for this slowdown is that the message on the server takes a very long time, and sometimes just fails.

My question is, how can I solve this? Check the signal quality? Poll known address? How do other solutions, such as Gmail, solve this problem? This should be a common scenario!

+7
source share
6 answers

Well, if you can potentially have thousands of tasks that all have to be completed, then, of course, they need to be managed. Have you thought about introducing your own ThreadPoolExecutor ? The documentation is very good and the class is easy to understand, but if you need examples, try these sites:

The advantage of this is that you can limit the maximum number of threads that you create, so you should not slow down the system if you limit the number of threads to a reasonable number (for Android, I would recommend no more than 20).

0
source

Is it possible to fine-tune the socket timeout and timeout? Thus, if your connection is slow and stopped, a timeout will occur and the transfer will fail.

After the connection / sending failed, you can retransmit later or do something else.

To set timeouts, you can use the following code:

 HttpParams httpParameters = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParameters, 30 * 1000); HttpConnectionParams.setSoTimeout(httpParameters, 15 * 1000); HttpClient client = DefaultHttpClient(httpParameters); // use client... 
0
source

We have a similar situation for our application. We considered signaling problems as reality, and this can happen at any time. One of the points that we follow is not to remove any content from the device unless we receive functional confirmation from the server and simply rely on the http status of the code. Both in a slow network and in cases where we can lose a signal all of a sudden, published our content, there were many cases when the data was received only partially. And so we decided to tell the server in some way (we learn through HTTP requests based on the request made by the device) so that the content is received. More than performance or network testing, the question you asked, we needed this behavior for our application reliability.

0
source

You should check the use of HTTP Range headers, for example here .

The server must write the payload to disk while reading and handle disconnects. The client cannot know how many bytes the payload actually reached the server, so it needs to synchronize with the server every time a network error occurs. Do not forget to handle problems with batteries and users, -)

0
source

If you want to wait for a better signal, perhaps the SignalStrength class, with its methods getCdmaDbm, getEvdoDbm and getGsmSignalStrength, what are you looking for.

0
source

Check it out: http://www.youtube.com/watch?v=PwC1OlJo5VM#!

advanced coding tips and tricks, bandwidth saving techniques, implementation patterns, the impact of some of the lesser-known API functions, and an understanding of how to minimize battery drain, ensuring that your application is a good citizen in a network of telecom operators.

0
source

All Articles