Outofmemoryerror error while downloading object list

Asked

Viewed 135 times

0

I am with this error when downloading an object from the webservice that has images that are converted to Base64. The point is that if this object is already saved in the local database of android the app works, I can load many objects at the same time and show on the screen, but now I’m downloading from the webservice this object, 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 when they are already in the cell the memory does not burst, now when I download it happens that.

This happens only in android emulator in version 2.3. at the top they work normal. I can even download an array with all 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 makes the download, I leave here to analyze

2 answers

3

  • Well, I’m following these tips, but the problem I still have to take care of when sending large images. In fact they have not even seen bitmap already I save directly in the bd, I only receive in Base64 convert and saved.

0

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

  • Thanks @franM but I’ve been reading about the android:largeHeap="true" and it does not work in versions 2.3, precisely in that of the problem

Browser other questions tagged

You are not signed in. Login or sign up in order to post.