Firstly you can chack if sharedpreference contains value than you can retrive this value by using getSharedPreference() function otherwise you can set value .
public static String checkVisitorId(){
public static final String DigitalEditionConstantPREFS_NAME="test";
SharedPreferences settings = getSharedPreferences(MyConstantPREFS_NAME, 0);
visitorID = settings.getString("VisitorID", false);
if(visitorID){
return visitorID;
} else {
visitorID="123";
SharedPreferences.Editor editor=settings.edit();
editor.putString("VisitorID", visitorID);
editor.commit();
return visitorID;
}
No comments:
Post a Comment