简体   繁体   中英

Android - Better Approach in Loading SD CARD Images

What is a better algorithm on loading or populating images from SD CARD, than storing each image path as Constants?

public final class Constants {

        public static final String[] IMAGES = new String[] {
            // Heavy images
        "file:///mnt/sdcard/folder/folder/folder/1.jpg",
        "file:///mnt/sdcard/folder/folder/folder/2.jpg",
        "file:///mnt/sdcard/folder/folder/folder/3.jpg",
        "file:///mnt/sdcard/folder/4.jpg",
        );
}

Basically I am learning the Universal Image Loader, and focusing on the grid view implementation in loading images. Right now the project is running but it is using the CONSTANT path. The thing is my images is stored in sd card.

LINK: https://github.com/nostra13/Android-Universal-Image-Loader/blob/master/sample/src/com/nostra13/example/universalimageloader/ImageGridActivity.java

LINK2: STORING PATH IN CONSTANT Strings https://github.com/nostra13/Android-Universal-Image-Loader/blob/master/sample/src/com/nostra13/example/universalimageloader/Constants.java

If it's a fixed set of images that never change that you know in advance, I don't see any problems with storing references to them in a String array, that's probably the best way to do it.

If you want to dynamically find images on the SD card at run-time you'd be better off scanning/getting a file list of the particular folder or folders you are interested in and passing that to the Image Loader. You can query the MediaStore or you can use Java IO methods.

There are many examples of SO how to do this:

Either way, Universal Image Loader should take a lot of the heavy-lifting on the bitmap-display side, so I wouldn't worry too much about that.

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