Android 执行与“清除数据”按钮相同的操作

Android 执行与“清除数据”按钮相同的操作,android,button,Android,Button,是否有一种方法可以以编程方式将数据按钮从设置->应用程序->管理应用程序清除到应用程序 或者,我想单击以删除所有SharedReference。如何执行此操作?删除所有应用程序首选项SharedReferences.Editor.clear方法。 有关详细信息,请参阅。删除所有应用程序首选项SharedReferences.Editor.clear方法。 有关详细信息,请参阅。Stackoverflow上的许多用户不了解的是;您想删除所有共享首选项文件。你不想一个接一个地清除它们 您只需从共享首

是否有一种方法可以以编程方式将数据按钮从设置->应用程序->管理应用程序清除到应用程序


或者,我想单击以删除所有SharedReference。如何执行此操作?

删除所有应用程序首选项SharedReferences.Editor.clear方法。
有关详细信息,请参阅。

删除所有应用程序首选项SharedReferences.Editor.clear方法。
有关详细信息,请参阅。

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();
    }
}

还要查看更多信息和其他删除共享首选项的方法。

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();
    }
}
还要检查更多信息和其他删除共享首选项的方法