Android - Clear Data Programmatically
Is it possible to clear the data for an Android application programmatically?
I am referring to the clear data functionality found in this image when to go to an application's settings on an Android device:
http://androidheadlines.com/images/android-how-and-when-to-clear-app-cache-or-data_waiod_0.jpg
Is there a function in Titanium that allows the data on an Android application to be cleared?
1 Answer
-
Accepted Answer
Yes you can. You can access the data files through
Titanium.Filesystem.applicationDataDirectory
to find all the files listed in the directory and then you can delete them one by one. It would probably look something like this://@author jtimberlake //get the data directory var directory = Ti.Filesystem.applicationDataDirectory; var dataDirectory = Ti.Filesystem.getFile(directory); var data = []; //I always make checks like this because you never know if(dataDirectory.exists()){ //get all sub-directories and file paths in your directory data = dataDirectory.getDirectoryListing(); //if the files still exist, destroy for( var i = 0; i < data.length; i++){ var fileToDelete = Ti.Filesystem.getFile(directory,data[i]); if(fileToDelete.exists()){ fileToDelete.deleteFile(); } } }