Android应用程序数据存储不断增加

发布于 2025-01-02 03:43:57 字数 457 浏览 4 评论 0原文

我正在开发一个 Android 应用程序,它基本上加载新闻文章列表,并在用户单击时在网络视图中打开它们。

我想知道的是,当我在“设置”->“应用程序”->“管理应用程序”中查看应用程序详细信息时,总存储大小不断增加。特别是,数据存储大小正在增加。当然,应用程序的大小是固定的。

据我所知,共享首选项占用数据存储。我不知道还有什么。在我的应用程序中,我只有 1 个复选框首选项和一个包含 4 个项目的列表首选项。

我还实现了 onSaveInstanceState() 方法,其中我只保存一个 int 值并在 onCreate() 期间再次读取。

数据存储大小的增加是正常的还是我遗漏了什么?也许我应该在代码中进行一些内存使用清理?

顺便说一句,我的应用程序有相当大的缓存大小,因为 webview 可能缓存了一些图像,但我不知道是什么导致数据存储不断增加。

I am developing an android app that basically loads up a list of news articles and opens them up in a webview upon user click.

What I'm wondering about is when I look at my app details in 'Settings->Applications->Manage Applications', the Total storage size keeps increasing. Particularly, the data storage size is increasing. The Application size of course, is fixed.

From what I know, the sharedpreferences take up data storage. I don't know what else. In my app, I just have 1 checkbox preference and a listpreference with 4 items.

I also implemented the onSaveInstanceState() method where I just save a single int value and read up again during onCreate().

Is the increasing data storage size normal or am I missing something? Maybe there should be some memory use cleanup I should do in my code?

By the way, my app has quite a big cache size due to the webview caching some images maybe but I don't know what makes the data storage keeps increasing.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

葬花如无物 2025-01-09 03:43:57

我知道这已经超过两年了,但对其他人可能有用。我发现问题出在 WebView 中,而不是在 SharedPreferences
我遇到了同样的问题,并通过以下方式重写 onPause() 方法解决了:

private WebView wv;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    wv = new WebView(this);
    setContentView(wv);
    wv.loadUrl("http://www.stackoverflow.com");
}

@Override
protected void onPause() {
    // TODO Auto-generated method stub
    super.onPause();
    wv.clearCache(true);
}

clearCache 方法采用一个布尔参数,让您指定是否要包含 WebView 存储的磁盘文件。如果启用它,您的数据使用量将显着减少。希望有帮助!

I know that is over 2 years, but it could be useful for someone else. I discovered that the problem resides in the WebView and not in the SharedPreferences
I had the same problem and solved by overriding the onPause() method in this way:

private WebView wv;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    wv = new WebView(this);
    setContentView(wv);
    wv.loadUrl("http://www.stackoverflow.com");
}

@Override
protected void onPause() {
    // TODO Auto-generated method stub
    super.onPause();
    wv.clearCache(true);
}

The clearCache method takes a boolean argument that lets you specify whether you want to include disk files that the WebView stores. If you enable it your data usage will significantly decrease. Hope it helps!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文