Note that there are some explanatory texts on larger screens.

plurals
  1. PODelete databases folder internal storage
    primarykey
    data
    text
    <p>I'm trying to create a reset app functionality for my application and I'm trying to delete all files from internal storage including <code>files folder</code>, <code>databases folder</code>and <code>shared preferences</code>. The problem is that not everytime when I try to delete these folder they are deleted. Sometimes the function which I use to delete the files returns false. In that case my application cannot work properly. Here is what I'm using :</p> <pre><code> @SuppressWarnings("static-access") public void deleteAllData(){ String cache = this.getCacheDir().toString(); Log.e("","dbPath : "+cache); File ChFolder = new File(cache); boolean cachee = deleteDirectory(ChFolder); Log.e("","Database Folder Delete Success : "+cachee); String server = rpc.getCurrentServerName(this); int userId = rpc.getUserId(this); String userDbPath = "/data/data/"+this.getPackageName()+"/databases/"+Integer.toString(userId)+"_"+server; File userDbFile = new File(userDbPath); boolean userDbFileTF = userDbFile.delete(); Log.e("","user Database Folder : "+userDbFileTF); String sysDbPath = "/data/data/"+this.getPackageName()+"/databases/stampii_sys_tpl.sqlite"; File sysDbFile = new File(sysDbPath); boolean sysDbFileTF = sysDbFile.delete(); Log.e("","user Database Folder : "+sysDbFileTF); // Delete Databases Folder : String dbPath = "/data/data/"+this.getPackageName()+"/databases/"; Log.e("","dbPath : "+dbPath); File dbFolder = new File(dbPath); boolean dbFold = deleteDirectory(dbFolder); Log.e("","Database Folder Delete Success : "+dbFold); // Delete Files Folder : String name = this.getFilesDir().toString()+"/users/"; Log.e("","path : "+name); File files = new File(name); boolean filesFol = deleteDirectory(files); Log.e("","filesFol : "+filesFol); } static public boolean deleteDirectory(File path) { if( path.exists() ) { File[] files = path.listFiles(); if (files == null) { return true; } for(int i=0; i&lt;files.length; i++) { if(files[i].isDirectory()) { deleteDirectory(files[i]); } else { files[i].delete(); } } } return( path.delete() ); } </code></pre> <p>Is there something I'm missing and how can I implement function like <code>Clear Data</code> in Android Settings which will delete the databases too. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload