Android 应用数据存储量不断增加 [英] Android app data storage keeps increasing

查看:54
本文介绍了Android 应用数据存储量不断增加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个 android 应用程序,它基本上加载了一个新闻文章列表,并在用户点击时在 web 视图中打开它们.

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.

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

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.

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

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?

顺便说一下,由于 webview 缓存了一些图像,我的应用程序有相当大的缓存大小,但我不知道是什么导致数据存储不断增加.

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.

推荐答案

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

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);
}

clearCache 方法采用布尔值允许您指定是否要包含 WebView 存储的磁盘文件的参数.如果启用它,您的数据使用量将显着减少.希望能帮到你!

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!

这篇关于Android 应用数据存储量不断增加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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