Android app data storage keeps increasing

十年热恋 提交于 2021-01-27 12:57:28

问题


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.


回答1:


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!



来源:https://stackoverflow.com/questions/9146425/android-app-data-storage-keeps-increasing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!