[英]Retrieving data from ArrayList
I have my Android application which needs to send data to server after certain limit of memory is reached. 我有我的Android应用程序,需要在达到一定的内存限制后将数据发送到服务器。 I am checking internal memory left using -
我正在检查内部存储器使用 -
StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath());
long bytesAvailable = (long)stat.getBlockSize() * (long)stat.getAvailableBlocks();
long megAvailable = bytesAvailable / (1024 * 1024);
Log.e("","Available MB : "+ megAvailable);
Suppose Available MB initially is 800MB. 假设可用MB最初为800MB。 I have an ArrayList of objects that keeps on adding elements every 10 seconds.
我有一个对象的ArrayList,每隔10秒就会继续添加元素。 Once my Available MB becomes 700MB, I want my data in ArrayList to be sent to server.
一旦我的可用MB变为700MB,我希望将ArrayList中的数据发送到服务器。
I wanted to know that when Available MB becomes 700MB- 我想知道当可用MB变为700MB-
a) how to retrieve data from ArrayList from 0th position until the current position(the position at which Available MB becomes 700MB) and send all at once. a)如何从ArrayList检索数据从第0个位置到当前位置(可用MB变为700MB的位置)并立即发送所有数据。
b) After sending clear the arraylist and start storing new data until Available MB becomes 600MB b)发送清除arraylist并开始存储新数据,直到Available MB变为600MB
When you add data to the arraylist you can keep a count. 将数据添加到arraylist时,您可以保持计数。 And when you invoke the method to find out if you have touched 700 mb you can send that count as a parameter.
当您调用该方法以确定您是否已触及700 mb时,您可以将该计数作为参数发送。
You can call the sublist method of ArrayList 您可以调用ArrayList的子列表方法
int to = 4;
int from = 0;
al.subList(from, to);
You can use removeAll()
to delete all the elements. 您可以使用
removeAll()
删除所有元素。
I exactly don't know how you can keep count of the the 'to' here. 我完全不知道你怎么能在这里保持'到'的数量。 But in any case , when you add data to the array you can keep a counter and send that over to the method you want to invoke.
但无论如何,当您向数组添加数据时,您可以保留一个计数器并将其发送到您要调用的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.