Android HashMap 序列化/反序列化
您好,我有一个位图 Hasmap,我需要将其存储在 Android 设备上,以便在下次应用程序启动时使用。
我的哈希图如下所示,最多包含 1000 个位图:
private static HashMap <String, Bitmap> cache = new HashMap<String, Bitmap>();
Hello I have a Hasmap of bitmaps which I need to store on the Android device to be used when next the application starts.
My hashmap looks like this, and contains up to 1000 Bitmaps:
private static HashMap <String, Bitmap> cache = new HashMap<String, Bitmap>();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能需要考虑创建 Map 扩展(通过使用 AbstractMap)并覆盖相关函数。一般来说,扩展的结构应该具有:
类似地,您的放置必须被覆盖才能放入磁盘以供以后使用,因此当您重新初始化应用程序时,您可以只创建地图扩展的实例。如果需要,您还可以按应用程序中最近使用的项目预加载哈希图。基本上,通过扩展 AbstractMap,您可以获得灵活性,而不会因这 1000 个位图而占用您的内存。希望这有帮助
You might want to consider create extension of Map (by using AbstractMap) and override the related functions. In general the structure of the extension should have:
Similarly your put has to be override to put to the disk for later use, so when you reinitialize your app you could just create an instance of the map extension. If you want, you could also preload the hashmap by most recently used items in the app. Basically, by extending the AbstractMap, you get the flexibilities without killing your memory with that 1000 bitmaps. Hope this helps