在Android的内存缓存 [英] Memory cache in Android

查看:213
本文介绍了在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.

推荐答案

每个Android应用程序有它自己的内存有限

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;

在一个正常的器件,这是一个最小的周围4MB(32/8)
32 MB的每个应用程序分配。

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

一个全屏幕网格视图充满图像的设备上使用800x480分辨率将使用1.5MB左右(800 * 480 * 4字节)。
800 * 480 * 4 =实际图像尺寸

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

这将缓存最小的约2.5页网格视图仅2.5图像存储在缓存memory.ieIn图像......当你上下滚动高达2.5的影像,从缓存中获取图像。 ..when用户移动到缓存中第三或第四image..the前两个图像缓存被清除,新的下载图像。

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.

机制:
在列表或网格视图,第一印象是从网络下载并存储在缓存用户滚动down..When用户向上滚动的图像是从缓存中提取(如果可用)。

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使用机制两类:

Android Uses Two Kind of Mechanism:

1.LRU缓存(用于内部应用程序内存)
2.Disk缓存(使用SD卡存储)

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

磁盘高速缓存code是从Android操作系统拉。
这种存储在SD卡的数据量有限。当插入的数据超出,最近最少使用的文件被删除并保存新文件。

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.

例如:
Facebook的Andr​​oid使用磁盘高速缓存。

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:

<一个href=\"http://developer.android.com/training/displaying-bitmaps/cache-bitmap.html#disk-cache\">http://developer.android.com/training/displaying-bitmaps/cache-bitmap.html#disk-cache

这篇关于在Android的内存缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆