At last, I am able to rename the sharedpreference file.
For reference, in my context the code is:
String fileName=etlistName.getText().toString();
File f=new File("/data/data/eywa.musicplayer/shared_prefs/"+PlayListName+".xml");
f.renameTo(new File("/data/data/eywa.musicplayer/shared_prefs/"+fileName+".xml"));
SharedPreferences mySharedPreferences=getSharedPreferences("list_of_playlist",Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = mySharedPreferences.edit();
editor.remove(PlayListName);
editor.putString(fileName, fileName);
editor.commit();
PlayListName=fileName;
And for deleting playlistName.xml
:
for (int i=0; i<selectedItems.size();i++)
{//remove the songs names from the playlist
SharedPreferences sp=getSharedPreferences(selectedItems.get(i),Activity.MODE_PRIVATE);
SharedPreferences.Editor ed=sp.edit();
ed.clear();
ed.commit();
//remove the play list name from the list_of_playlist
SharedPreferences.Editor editor = mainPref.edit();
editor.remove(selectedItems.get(i));
//delete .xml file
File f=new File("/data/data/eywa.musicplayer/shared_prefs/"+selectedItems.get(i)+".xml");
if(f.delete())
System.out.println("file deleted")
editor.commit();
}
selectedItems.clear();