• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Best Practice Pre-Loaded Images

Millamber

Lurker
Dec 12, 2013
6
0
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.

TIA

Millamber
 
Thanks.

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.

TIA

Millamber
 
Upvote 0
Upvote 0
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. :)
 
Upvote 0
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.
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones