Android - Clear Data Programmatically

You must Login before you can answer or comment on any questions.

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
    //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]);

— answered 4 years ago by James Timberlake
answer permalink
  • Thank you, your response seems to be what I am looking for.

    — commented 4 years ago by Tuan Nguyen

  • nothing happens.. it takes data from the cache only even after using the above code.

    — commented 3 years ago by Dhananjay Choudhari

  • cache is different from applicationdatadirectory. to clear the cache you must empty the Ti.Filesystem.applicationCacheDirectory instead of the applicationDataDirectory

    — commented 2 years ago by Peter Beukema

  • Show 2 more comments

Your Answer

Think you can help? Login to answer this question!