Android Tech

The more we share, the more we get

Google Map (Part 2) – Delete files stored by Google Map on your device when application runs


When you start your application which already load map for at least 1 time, Google Map will load necessary files to display map on your device.

If you don’t remove them when application exits, for a long time, this will make your phone storage is full. So, I will show you how to delete these files completely.

We will use function getFilesDir() to get files stored on application data storage (data/data/<your main package>) which Google Map use to store their files.

Code as follow:

public static boolean DeleteDirectories(File d) {
String[] children = d.list();
for (int i = 0; i < children.length; i++) {
boolean success = new File(d, children[i]).delete();
if (!success) {
return false;
}
}
return d.delete(); //Delete empty directory
}

public static void DeleteCache(Context context) {
try {
File d = context.getFilesDir();
if (d != null && d.isDirectory()) {
DeleteDirectories(d);
}
} catch (Exception e) {
// TODO: handle as you please
}
}

I will create a class named “commonProcess” and implement above functions. After that call them in Destroy event of application. So that, every time user quit application, these files will completely removed. If user just move around in their application, the state of map is still have.



Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: