Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Memory cache in Android [closed]

Tags:

android

I am trying to store one video in memory cache, after video is completed it be deleted from cache. And during play back that video file can't be deleted from cache.

like image 588
Naveen Avatar asked Dec 21 '22 07:12

Naveen


1 Answers

Every Android Application has its own limited memory

// Get max available VM memory, exceeding this amount will throw an
// OutOfMemory exception. 
 final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);

// Use 1/8th of the available memory for this memory cache.
 final int cacheSize = maxMemory / 8;

On a normal device this is a minimum of around 4 MB (32/8) 32 MB allocated per application.

A full screen Grid View filled with images on a device with 800x480 resolution would use around 1.5MB (800*480*4 bytes). 800*480*4 = actual Image size

This would cache a minimum of around 2.5 pages of images in memory.i.e.In Your Grid View only 2.5 images are stored in cache...when you scroll up and down up to 2.5 images,it get the image from cache...when user moved to 3rd or 4th image..the first two images cache is cleared and new download image in cache.

Cache Mechanism is used Mainly for Smooth scrolling of Images in list of Grid View.

Mechanism: In list or Grid view,first images are downloaded from network and stored in cache as user scrolls down..When user Scrolls up the images is fetched from cache if it is available.

Android Uses Two Kind of Mechanism:

1.LRU Cache(Internal application memory used) 2.Disk Cache(sdcard memory used)

Disk Cache code is pulled from Android os. This stores limited amount of data in sdcard. When inserted data exceed,least recently used file is deleted and stores new file.

ex: Facebook Android uses Disk Cache.

Cache Memory is cleared in Application program level or Settings>Manage Applications>App Name.

Every application has its own Cache Memory, one application cannot access the cache memory of other application..

For More information visit:

http://developer.android.com/training/displaying-bitmaps/cache-bitmap.html#disk-cache

like image 63
user2060635 Avatar answered Jan 06 '23 20:01

user2060635