OutOfMemoryError error while downloading object list

0

I'm having this error while downloading a webservice object that has images that are converted to base64. The question is that if this object is already saved in the local android database the app works, I get load many objects at once and show on the screen, but now I'm downloading from the webservice these object, down one by one, and some are giving this error due to the amount of images they have.

I do not understand why if these objects are already in the cell the memory does not burst, now when I download it happens.

This happens only in the Android 2.3 emulator. in the upper run normal. I can even download an array with all the objects and their images.

Method responsible for downloading

public class Sincronismo {

    public static String GET(Context context, String endereco){
        //Verifica se existe conexão com a internet
        if(!existeConexao(context))
            return K.FALHA_CONEXAO;
        InputStream inputStream = null;
        HttpClient httpClient = new DefaultHttpClient();
        String result = K.FALHA;
        try{

            HttpGet httpGet = new HttpGet(endereco);
            HttpResponse httpResponse = httpClient.execute(httpGet);
            inputStream = httpResponse.getEntity().getContent();
            if(inputStream!=null)
                result = inputStreamParaString(inputStream);
            else
                result = K.FALHA;
        }catch(UnsupportedEncodingException e){
            e.printStackTrace();
        }catch(ClientProtocolException e){
            e.printStackTrace();
        }catch(IOException e){
            e.printStackTrace();
        }
        return result;
    }

    private static String inputStreamParaString(InputStream in) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(in));
        String line="";
        String result="";
        while((line = br.readLine())!=null)
            result += line;

        in.close();
        return result;
    }
}

This is the method that downloads, I leave here to analyze

    
asked by anonymous 09.01.2015 / 18:47

2 answers

3

If you have a high resolution image, you should decrease them. See the topic under Down in a reduced version in memory.

link

link

How to avoid these errors: link

For a deepening:

link

link

Font: link

    
09.01.2015 / 23:52
0

Place android:largeHeap="true" in your manifest .

    
26.01.2015 / 16:36