1. Are you ready for the Galaxy S20? Here is everything we know so far!

Best Practice Pre-Loaded Images

Discussion in 'Android Development' started by Millamber, Dec 12, 2013.

  1. Millamber

    Millamber Lurker
    Thread Starter

    I am developing an app that I wish to have pre-loaded with product images.

    Currently, I am accessing them from the resources folder 'drawable'.

    However, I also want the user to be able to add to list of products later by retrieving product information and products from a web server.

    I can't access the resources folder at run time to save the images, so I need to have a single place to store them and retrieve them later.

    I have tried saving to the application directory, but am not having much success.

    Could some advice on the best practice in this situation. I believe that storing images in the database is not considered good practice.



    1. Download the Forums for Android™ app!


  2. Rukbat

    Rukbat Extreme Android User

    I cna't help you with the rest, but , You'd have to select the BLOB from the database and store it as a picture before you can use it - in some directory, which would probably be the better place to store it.
  3. AARON45

    AARON45 Lurker

    I like your good work.
  4. Digital Controller

    Digital Controller The Real Bass Creator

    I have moved this thread to the Application Development forum since you are looking for assistance for developing an application.

    Hope this helps, feel free to PM me if you don't like this :)
  5. Millamber

    Millamber Lurker
    Thread Starter


    For the moment I have decided to store these images in the Assets directory and copy them to the application directory when the application is first installed.

    Then for any subsequent images that are saved at runtime, they can be saved to the same application directory.

    Still would be interested in hearing from anyone about this approach and/or any best practice patterns for this scenario.


  6. alostpacket

    alostpacket Over Macho Grande?

  7. Millamber

    Millamber Lurker
    Thread Starter

    Thanks alostpacket,

    These resources look very useful, but I would like to clarify some points if I may.

    I understand the use of the drawable for storing items like logos, icons and also the use of the external directory for storing items that are downloaded etc.

    What I would like clarification on is:

    I have an app that deals with products like in a shopping list.

    I want to ship the app with a collection of 100 preloaded products as examples, but I also want the user to be able to contact a remote source to add additional products.

    My thinking is that in a list view, I don't want the list view to be looking in two different places for the source of the image i.e. drawables for pre-loaded products and an external directory for newly added products.

    Also I would like the images to be available on the device so that they display whilst no network connectivity is available.

    My current approach is to put logos, icons etc in the drawable directory
    Put pre-loaded product images in the assets directory
    On first install copy those images to the private application directory in a sub-folder of products.
    When new products are added, save these to the products folder of the application directory.
    Using this approach also means that the images will be uninstalled if the application is ever removed from the device.
    I have already written my product adapter to use of cache of images and to load the product images and produce thumbnails for the list view.

    The library solution you provide looks good, but doesn't address my main concern here about having images in different locations depending on whether they were pre-installed or not.

    I would be very interested in hearing your (or anyone else's) thoughts on this approach.

    Thanks for your reply.

    Much appreciated. :)
  8. alostpacket

    alostpacket Over Macho Grande?

    There is nothing wrong with using the list adapter to determine where to look for images.

    I see what you are getting at though. Still, for dynamic content I would just load it from the web. Don't try to over optimize.

    Volley actually provides a way to set a default loading and error image in addition to the URL. You provide it with drawable ids for what to show while loading and/or what to show on error. Then it will cache the image in memory and on disk and use the URL to know when to get a fresh copy

    Volley is the library used in the Google Play store app itself.

Share This Page