Tag:android import databases Database files
/* * pieces : datacleanmanager.java * description Description: main functions are to clear the inside/out cache, clear the database, clear the sharedpreference, clear files and clear the custom directory */ import java.io.File; import android.content.context;import android.os.environment; /** * the application Data Purge manager * /publicclass datacleanmanager { /** * clear this app internal cache (/data/data/ Com.xxx.xxx/cache) * * @paramcontext */ publicstaticvoid Cleaninternalcache (Context context) { Deletefilesbydirectory (Context.getcachedir ()); } /** * Clear all databases for this application (/data/data/com.xxx.xxx/databases) * * @param context */ publicstaticvoid cleandatabases (Context context) { deletefilesbydirectory (New filE ("/data/data/" + context.getpackagename () + "/databases")); } /** ** Clear this application sharedpreference (/data/data/com.xxx.xxx/shared_prefs ) * * @param *context */ publicstaticvoid cleansharedpreference (Context context) { deletefilesbydirectory (New file ("/data/data/" + context.getpackagename () + "/shared_prefs")); } /** * clear the application database by name * * @param context * @paramdbName */ publicstaticvoid cleandatabasebyname ( context context, Stringdbname) { context.deletedatabase (dbName); } /** * clear the content under/data/data/com.xxx.xxx/files * * @param context */ publicstaticvoid cleanfiles (Context context ) { deletefilesbydirectory (Context.getfilesdir ()); } /** ** clear the contents of the external cache (/mnt/sdcard/ Android/data/com.xxx.xxx/cache) * * @param *context */ publicstaticvoid cleanexternalcache (Context context) { if (Environment.getexternalstoragestate (). Equals ( environment.media_mounted) ) { &Nbsp; deletefilesbydirectory (Context.getexternalcachedir ()); } } /** * Clear the file under the custom path, use caution, please do not delete it by mistake. And only supports file deletion in directory * * @param filePath */ publicstaticvoid Cleancustomcache (String filepath) { deletefilesbydirectory ( New file (FilePath)); } /** * Erase all data from this app * * @param context * @paramfilepath */ Publicstaticvoid cleanapplicationdata (Context context,string... filepath) { cleaninternalcache (context); Cleanexternalcache (context); cleandatabases (context); &nbSp;cleansharedpreference (context); cleanfiles (context); for (String filepath : filepath) { cleancustomcache (FilePath); } } /** * Delete method This will only delete files under a folder, If the incoming directory is a file, it will not be processed * * @param directory */ Privatestaticvoid deletefilesbydirectory (file directory) { if (directory != null&& directory.exists () && Directory.isdirectory ()) { for ( File item : directory.listfiles ()) { item.deLete (); } } }}
for Performance testing for apps I usually use:www.ineice.com
Share: Android clears local data cache code