Hello! I have several Activities, one of them is to activate it with the settings of the application that I create. In the settings, I created a button, when clicked, all of the application settings should be reset, including all shared preferences, which are contained in different Activities. This method is implemented
public class Settings extends MainActivity {
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_settings); View view = findViewById(R.id.buttonReset); if (view != null) { view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { clearData(Settings.this); } }); } } public static void delete(File file, boolean deleteDir) { if (file.isDirectory()) { File[] files = file.listFiles(); if (files != null) { for (File f : files) { delete(f, true); } } if (deleteDir) { file.delete(); } } else { file.delete(); } } public static void clearData(Context context) { File files = context.getDir("tmp", Context.MODE_PRIVATE); delete(files.getParentFile(), false); }
}
Settings are deleted, because in the settings of the smartphone in the "Application Management" tab in the settings of the application in the "Data" line is 0.00B. That is, the data is deleted. But all shared preferences for some reason did not leave. That is, the whole progress of the game (levels, coins, etc.) is preserved, because it is contained in shared preferences. Tell me what I'm doing wrong. And is there another way to solve the problem? Thank.