2011-12-05 28 views

回答

2

要删除所有应用程序首选项SharedPreferences.Editor.clear()方法。 有关详细信息,请参阅this documentation

0

Stackoverflow上很多用户不明白的是;你想删除全部共享偏好文件。你不想一个接一个地清除它们。

您可以简单地从你的共享偏好文件夹中的所有文件删除:

Context r = getActivity(); 
    File dir = new File(r.getFilesDir().getParent() + "/shared_prefs/"); // files directory is a sibling of the shared_prefs directory 
    String[] children = dir.list(); 
    for (String aChildren : children) { 
     r.getSharedPreferences(aChildren.replace(".xml", ""), Context.MODE_PRIVATE).edit().clear().commit(); 
    } 
    try { 
    Thread.sleep(800); 
    } 
    catch (InterruptedException e) { } 
    for (String aChildren : children) { 
     new File(dir, aChildren).delete(); 
    } 
} 

同时检查these answers更多的信息和删除共享偏好的其他方式。

相关问题