John Ng
John Ng

Reputation: 899

Android app data storage keeps increasing

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.

Upvotes: 4

Views: 4425

Answers (1)

Angelo
Angelo

Reputation: 937

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!

Upvotes: 4

Related Questions