Search code examples
androidxmlpreference

Check if a private preference has been created?


I want to check if a xml file exists. The xml is the private preference of an activity. And I want to read from my main activity when app starts. How can I check it?

I don't need read the file, only to know if exists or not.


Solution

  • You can check with the help of this, It seems that it's not good solution but you can check your shared prefrence's file.

    File f = new File("/data/data/"+context.getPackageName()+"/shared_prefs"+"/MyFile.xml");
    if(f.exists()){
        Log.v("LOG", "Exist");
    }else{
        Log.v("LOG", " Not Exist");
    }