android - getSharedPreferences using R.something? -


with these lines:

string app_name = "@string/app_name"; sharedpreferences sharedpreferences = getsharedpreferences(app_name, 0); 

i illegalargumentexception:

file @string/app_name.xml contains path separator

if this:

sharedpreferences sharedpreferences = getsharedpreferences("myappname", 0); 

it works fine how use without hard-coding app name? can't use r.string.app_name because int.

you can this

string app_name = getresources().getstring(r.string.app_name); sharedpreferences sharedpreferences = getsharedpreferences(app_name, 0); 

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -