简体   繁体   中英

what happen when memory is full in image gallery

there is a image gallery app which download images online. I want to know what will happen if phone memory/SD card get full; If an error will appear then what should I do?

It will through IOException if no memory is left in sdcard. But if you know the size of file which you are downloading then you can check for sufficient memory and thus can avoid IOException.

Edit: Catch Exception

try
{
   //your code here
}
catch(IOException ex)
{
   //do stuff when exception caused.
}

if you don't know how to use/catch exception. Please google it.

This catches an OutofMemory error, but should check for other exceptions, too

    URL aURL = null;
    Bitmap bm = null;
    try {
        final String imageUrl = CMSServer + url;

        aURL = new URL(imageUrl);
        URLConnection conn = aURL.openConnection();

        InputStream is = new BufferedInputStream(conn.getInputStream());

        is = new BufferedInputStream(conn.getInputStream());
        bm = BitmapFactory.decodeStream(is, null, options);

        is.close();
    } catch (OutOfMemory oom) {
         // do something 
      }
    }
    return bm;
}

The analogy can be made what if a class cannot adjust more students ?

So according to me :- 1. you can follow "Precaution is better than cure"

  1. first of all you will check the sdcard itself and if its say >1MB then you will get the image.

  2. Even if the error comes you can prompt user to delete older images to allow new images like we used to have older phones where msg memory was limited and it will ask to remove older messages to allow new messages.

  3. Still if you get the error then perhaps i cannot exactly figure out what to do except showing the "Out of memory exception" to user.

Thanks and hope it helps.... :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM