2024-07-12
한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina
In Android, there are many ways to eliminate data saved inside the application. This data may be stored in SharedPreferences, SQLite database, files (including cache files), or Content Providers. The following are several common methods to eliminate this data:
SharedPreferences:
To delete all data in SharedPreferences, you can simply callSharedPreferences.Editor.clear()
method, and then commit the changes.
- SharedPreferences sharedPreferences = getSharedPreferences("your_prefs_name", MODE_PRIVATE);
- SharedPreferences.Editor editor = sharedPreferences.edit();
- editor.clear();
- editor.apply(); // 或者使用 editor.commit();
SQLite Database:
DELETE
SQL statement.Context.deleteDatabase(String name)
method.document:
Apps may create files in internal storage or external storage to save data. To delete these files, you can useFile.delete()
method.
- SharedPreferences sharedPreferences = getSharedPreferences("your_prefs_name", MODE_PRIVATE);
- SharedPreferences.Editor editor = sharedPreferences.edit();
- editor.clear();
- editor.apply(); // 或者使用 editor.commit();
Context.deleteCacheDir()
to delete the entire cache directory.Content Providers:
Uninstall apps:
PackageManager.uninstallPackage(String packageName)
(Note, however, that this method is generally only available for system apps or apps with specific permissions).Clear data within the app:
Using ADB Tools from Android Studio:
adb shell pm clear <package_name>
) to clear the app's data.Use the "Clear Data" button (in settings):