好办法,在Android应用程序生命周期中缓存数据? [英] Good way to cache data during Android application lifecycle?

查看:110
本文介绍了好办法,在Android应用程序生命周期中缓存数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

保持我的问题总之,我已经创建了一个应用程序有3个活动,其中A - 类名单,B - 产品清单,C - 单个项目。在B和C的数据显示,从网上XML解析。但是,如果我去到A - > B1 - > C,然后再返回到A,然后回到B1,我想有它的数据缓存的地方,所以我就不必再次请求XML

keeping my question short, I have created an application with 3 activities, where A - list of categories, B - list of items, C - single item. Data displayed in B and C is parsed from online XML. But, if I go through A -> B1 -> C, then back to A and then back to B1, I would like to have its data cached somewhere so I wouldn't have to request the XML again.

我是新来的Andr​​oid和Java编程,我GOOGLE了很多,但仍无法找到(或根本就没有一个想法去哪里找)的方式做我想做的。

I'm new to Android and Java programming, I've googled a lot and still can't find (or simply do not have an idea where to look) a way to do what I want.

会存储所有收到的主要活动数据(包含HashMap?ContentProviders?),然后传递给B和C(如果他们那是以前同样的要求)是一个好主意?

Would storing all received data in main activity A (HashMaps? ContentProviders?) and then passing to B and C (if they get same request that was before) be a good idea?

推荐答案

一个简单快速的方法来缓存信息,或者跟踪应用程序的状态,就是在描述延长的应用程序的< A HREF =htt​​p://blog.tomgibara.com/post/126377651/global-application-state-in-android>这篇博客。

A simple and fast way to cache information or to keep track of the application state, is to extend the Application as described in this blog post.

本博客文章忘记补充一点,你必须设置你的 CustomApplication 的清单中类,如:

This blog post forgets to add that you have to set your CustomApplication class in the manifest, like:

<application [...] android:name="CustomApplication">

在我的项目中,我首先通过getInstance坚持单身风格。

In my projects I stick to the singleton style via getInstance.

更多资源:这个答案,的Global变量在Android应用和<一href="http://www.bryandenny.com/index.php/2010/05/25/what-i-learned-from-writing-my-first-android-application/">this博客文章。

这篇关于好办法,在Android应用程序生命周期中缓存数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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