In my app, I fetching data from the server in the form of JSON. The data is around 1.5 MB. The app works but sometimes it crashes while fetching data from server giving Out
If you do not have enough memory to store your string you can: free some memory, reduce memory consumtion and do not store string in memory.
In your case you need:
Options:
Just add this to the <application />
tag in your manifest:
android:largeHeap="true"
Try like this,
private String sendPostRequest(String url, List<NameValuePair> params)
throws Exception {
String ret = null;
BufferedReader bufferedReader = null;
HttpClient httpClient = new DefaultHttpClient();
HttpPost request = new HttpPost(url);
try {
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(params);
request.setEntity(entity);
HttpResponse response = httpClient.execute(request);
bufferedReader = new BufferedReader(new InputStreamReader(response
.getEntity().getContent()));
String line = "";
while ((line = bufferedReader.readLine()) != null) {
ret =ret +line;
}
bufferedReader.close();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (bufferedReader != null) {
try {
bufferedReader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return ret;
}