[英]Delete app folder (with Shared Preferences and downloaded images)
在我的應用程序中,我有5個帳戶。 用戶可以使用“注銷”按鈕,而不是輸入密碼並登錄到另一個帳戶。 所以我的問題是:如何刪除所有共享的首選項( 內部存儲)(它們很多-大約110-120個文件)和所有圖片(大約10個)?
我正在嘗試使用以下代碼刪除共享首選項:
File sharedPreferenceFile = new File("/data/data/"+ getPackageName()+ "/shared_prefs/");
File[] listFiles = sharedPreferenceFile.listFiles();
for (File file : listFiles) {
file.delete();}
但是我不能這樣做,因為'File.delete()'的結果被忽略了
在那里,我如何看待“共享首選項”的價值(如果需要):
SharedPreferences sp = getSharedPreferences("timeTable", 0);
SharedPreferences.Editor sedt2 = sp2.edit();
sedt2.putString("timeTable", place1.getText().toString());
sedt2.apply();
以及如何將圖像和位圖放置到應用程序目錄中:
bitmap_backgroundImage = BitmapFactory.decodeByteArray(data, 0, data.length);
ContextWrapper cw1 = new ContextWrapper(getApplicationContext());
File directory = cw1.getDir("backgroundimage", Context.MODE_PRIVATE);
if (!directory.exists()) {
directory.mkdir();}
File mypath1 = new File(directory, "backgroundimage.png");
FileOutputStream fos = new FileOutputStream(mypath1);
bitmap_backgroundImage.compress(Bitmap.CompressFormat.PNG, 100, fos);
fos.close();
是否有任何代碼可以單擊按鈕后刪除圖片和共享首選項?
要清除SharedPerferences,您必須編寫
sp.edit().clear().commit()
刪除文件系統中存儲的圖像
for(File file: dir.listFiles()) {
file.delete();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.