I am trying to send multiple Json string[each 1 MB] at a time to PHP Server. When i tried to send 10 records its working fine. But if it exceeds 20 records it says OutOfMemoryException
. I seen that android memory size limit t0 15MB - 16MB. But haven't got any clue how to resolve this,
I am using the below code to send multiple records at a time.
/** Upload Data*/
private void submitUploadData(String url, Map<String, String> param)
throws IOException {
URL siteUrl;
try {
siteUrl = new URL(url);
HttpURLConnection conn = (HttpURLConnection) siteUrl
.openConnection();
conn.setRequestMethod("POST");
conn.setDoOutput(true);
conn.setDoInput(true);
DataOutputStream out = new DataOutputStream(conn.getOutputStream());
String content1 = "";
Set getkey = param.keySet();
Iterator keyIter = getkey.iterator();
String content = "";
for (int i = 0; keyIter.hasNext(); i++) {
Object key = keyIter.next();
if (i != 0) {
content += "&"; //Crashing here
}
content += key + "=" + param.get(key); //Crashing here
System.out.println("Content" + content);
}
System.out.println(content);
out.writeBytes(content.trim());
out.flush();
out.close();
BufferedReader in = new BufferedReader(new InputStreamReader(
conn.getInputStream()));
String jsonresponse = "";
while ((jsonresponse = in.readLine()) != null) {
System.out.println(jsonresponse);
if(!jsonresponse.equals("Authorisation Successful")){
updateUploadRecords(jsonresponse);}
}
in.close();
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
content
string in the worst possible way. – Perception Mar 6 at 9:46StringBuilder
, its much more efficient. – Perception Mar 6 at 10:00