What is the ideal place to cache images?

I am fetching a lot of thumbnails in my application from a remote server and lazy-loading these in a list view.

The image fetches run in a background AsynTask and when completed the fetched images are stored in a HashMap using SoftReferences.

This works just fine but when the images in the cache gets GC’d, the fetches have to be rerun.

I could have stored them on the SD card so there would be no re-fetching.

But I did not take this approach because of the clutter it would create on the SD card.

Are there perhaps alternatives to these sorta like temporary folders that can be cleared when activity/app finishes/exits?

What is the "ideal place" to cache images? Any advice, example projects, or pointers would be appreciated.

Asked by: Julian432 | Posted: 24-01-2022

Answer 1

You should check files data storage options:
Files are being saved in the applications directory, so there is no mess anywhere. Files will be finally removed with the app. You can also implement some method which will clear the cache when the app starts (for example remove files older than 2 weeks).

Answered by: Fiona916 | Posted: 25-02-2022

Answer 2

You should be able to locate a SQLite DB on the SD card. This would let you have a fairly clean interface/cache space while keeping data off the very limited internal phone memory. You can specify the location of the DB by calling openOrCreateDatabase(String path, SQLiteDatabase.CursorFactory factory). It may be more work than you'd like to put in, but you should be able to clear ou the DB when you application is unloaded with a line or two of code.
More from the documentation here: http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html

Answered by: Marcus142 | Posted: 25-02-2022

Similar questions

How to add 3 images in a canvas in android

I have 3 images that I want to add one after other on a canvas. This is my code:- public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ImageButton im1 = (ImageButton)findViewById(R.id.btnPN); im1.setBackgroundDrawable(getImage()); } public BitmapDrawable getImage() { Drawable image1 = getResources().getDrawable(R...

android - List of images that wraps

I have a LinearLayout with fixed view. I dynamically inject images in it (ImageViews) but I dunno in advance how many of them will be inserted. I'd like to have a layout where images wrap and go to a new line authomatically when they exceed the available width of the father (LinearLayout) how do you recommend I should move? thanks a lot

android - Load large images into Bitmap?

I'm trying to make a basic application that displays an image from the camera, but I when I try to load the .jpg in from the sdcard with BitmapFactory.decodeFile, it returns null. It doesn't give an out of memory error which I find strange, but the exact same code works fine on smaller images. How does the generic gallery display huge pictures from the camera with so little memory?

android - digital compass problem

I am creating an augmented reality application and I noticed that the stored locations don't appear appear on the correct direction if I try to use the camera view (using layar or wikitude API). The problem is that the digital compass doesn't show north correctly when you try to look at the known objects through the camera view. If align the phone with the ground (look at my shoes) the locations appear at the screen accord...

android - How to remove labels from a MapView?

I am trying to make a satellite view (via a MapView) without labels. How can I do this?

android - Custom title with image

i'm creating custom title for activity by disabling standard one and managing everything myself. I wonder if it's possible to replace/theme standart title to my needs. I can customize size, background image, and text via themes by changing windowXYZStyle items. The only thing i couldn't find - how i can add image instead of text. I've tried requestWindowFeature(Window.FEATURE_CUSTOM_TITLE) and ...

canvas - Android draw with blur

I need do draw on Android's Canvas using Blur effect, it is a very simple feature, I need to draw a circular area, which is blurred (the foreground) and the background transparent, I can do everything with manipulating the colour alpha to do it with custom transparency but I need it to be blurred instead of transparent.. any ideas?

layout - How to resize a android webview after adding data in it

In a layout (linear, vertical) hierarchy I've got several views and one of them is a WebView. They all have same parameters: android:layout_width="fill_parent" android:layout_height="wrap_content" For all views, the spacing between elements is correctly handled but for the Webview there is a lot of spaces after the displayed text inside. I set the (HTML) text of the webview in the ...

How to find easily the source of an android class

I know I can access android source code from https://android.googlesource.com, but it's hard to select the right git repo if I only know the package and the name of an android class. Isn't there a way to locate a file in https://android.googlesource.com?

camera - Android Intent Save Path

At the moment I am using two intents. One for voice-recording, another for the camera: Intent photoIntent = new Intent("android.media.action.IMAGE_CAPTURE"); startActivityForResult(photoIntent, ACTIVITY_TAKE_PHOTO); Intent voiceIntent = new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION); startActivityForResult(voiceIntent, ACTIVITY_RECORD_SOUND); My aim is to put an Extra to each of t...

Android "hover" event in custom layout

I have a custom layout that I have written that basically just displays a bunch of ImageViews. I am handing onTouch events for all the ImageViews in my layout. However, if a user touches one imageView and then drags over another ImageView, I would like to be able to handle that as well. How would I go about capturing this behaviour?

How to create a tree view in Android?

There are no controls in Android that provide Tree-like View. There is an ExpandableList View which I suspect could be used to creating one. Have you tried imlpementing such a control? How would one implement such a control in Android?

android how to scroll to see all the widget of the view

In one of my androids activities, I have several widget in a vertical linearlayout. The length of this layout is bigger than the screen and thus I cannot see the widget at the bottom. In the Emulator, is there a special scroller to implement or a particular action to do to be able to scroll up and down ? Thanks a lot, Luc

Still can't find your answer? Check out these communities...

Android Google Support | Android Community | Android Community (Facebook) | Dev.io Android