I want to remove sharedPreference details;I did like this, but not working:
SharedPreferences myRoutes = this.getSharedPreferences("myDefalutRoute", MODE_PRIVATE);
public void onExitAction(View botton){
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);
finish();
SharedPreferences myPrefs = this.getSharedPreferences("myLogedPrefs",MODE_WORLD_READABLE);
myPrefs.edit().remove("myLogedPrefs");
myPrefs.edit().clear();
myPrefs.edit().commit();
myRoutes.edit().remove("myDefalutRoute");
myRoutes.edit().clear();
myRoutes.edit().commit();
moveTaskToBack(true);
}
After exit the application & go to data\data\package\myLogedPrefs.xml contain values.
How we can remove the SharedPreferences data?
Please help me..
Thanks in advance;
Are you sure onExitAction() is being called? Where are you calling it from. Put in some logging to make sure it’s being called. And as J_Andr mentioned, you probably want to move this code or call the function from the onDestroy method of the initial Activity of the application.