2

I want to delete the cache files in my application programmatically.

How do i go about doing this in code?

I want to launch a service (which i already have set up to do this).

FYI - IDK why my acceptance rate is low. Ive accepted most or all of my answers.

yoshi24
  • 3,147
  • 8
  • 45
  • 62

1 Answers1

7

I assume you're talking about the Context's cache directory?

This is one way:

File cacheDir = context.getCacheDir();

File[] files = cacheDir.listFiles();

if (files != null) {
    for (File file : files)
       file.delete();
}
Brandon O'Rourke
  • 24,165
  • 16
  • 57
  • 58