I'm working on an application that fetches data from a bluetooth device. But sometimes it throws OOM error while performing some operation
Here is the code
The Following way I am storing the data in an ArrayList<String>
private ArrayList<String> dataList; 
if (response.compareTo("Some Filter") != 0 //response is of String type
{
    dataList.add(response);
}
And in the below for each loop it throws OOM error
for (String s : dataList) { 
if(s.length()>8)
    dataList.set(dataList.indexOf(s), s.substring(8));  
else
    dataList.set(dataList.indexOf(s), "");
}
String downloadedData = "";
for (String s : dataList) {
    downloadedData += s; //This one is the 280th line throwing OOM
}
So far I have read this post but it gives solutions for reading data in json or web response
And i know OOM error can't be handled but prevented by following a good Architecture
And there are also these two Callbacks for Android
But i am not sure how to go for the solution !!
The crash Stacktrace is:
java.lang.OutOfMemoryError: Failed to allocate a 106990 byte allocation with 5840 free bytes and 5KB until OOM
 at java.lang.AbstractStringBuilder.enlargeBuffer(AbstractStringBuilder.java:95)
 java.lang.AbstractStringBuilder.append0(AbstractStringBuilder.java:146)
 at java.lang.StringBuilder.append(StringBuilder.java:216) 
 at Class_name.java:280.
Any help is appreciated :)
 
     
     
     
     
    