android - Variable not declared until set in preferences -


i'm working on app works database , offers option create backup on external storage. app gets backup directory preferences, since it's not set when run app first time, use default path instead, getting path external storage , creating directory there.

for this, use global string value keeps backup path. here's problem - when run app first time, declare default path in oncreate() method. when try write path log, works. have onclick() method, listen click on button, calls dialog export/import options. when try write backup path log here, string empty.

variable shouldn't issue, because here's interesting thing - when go preferences , set backup path there (which saved string variable same way before), can variable onclick method , works fine.

just record, tried setting different path , i've been choosing same path in preferences used manually in oncreate method.

any ideas issue? can write whole condition backup path used in oncreate onclick method , solve issue, avoid duplicite code , it's bugging me.

edit:

here's code of condition use in oncreate method.

location = preferencemanager.getdefaultsharedpreferences(this); if(location.getstring("backup_location", "").equals("")) {     string state = environment.getexternalstoragestate();      if(environment.media_mounted.equals(state)) {         file file = new file(environment.getexternalstoragedirectory().tostring() + "/simpledbmanager_backup");          if(!file.exists()) {             file.mkdirs();         }          this.backup = file.getabsolutepath().tostring();     } } else {     this.backup = location.getstring("backup_location", ""); } 


Comments

Popular posts from this blog

How to run C# code using mono without Xamarin in Android? -

c# - SharpSsh Command Execution -

python - Specify path of savefig with pylab or matplotlib -