1

I am creating an android application where I need to use the IP of my server in many different activities to access PHP files. Every time I connect to a new network, I manually change all the IPS in ALL activities.

My question is, can I declare a String resource in my Values-->Strings.xml, and just change it there, so that all modifications are done at once?

I know that we can access a string resource in an xml file using " @string/my_string_var", where my_string_var is the variable name for my actual string.

Can I use a string resource in any of my activities, like this:

final String IP = @string/final_ip;

Batwoman05
  • 215
  • 1
  • 2
  • 9
  • 2
    Did you read the documentation about resources? It's here: https://developer.android.com/reference/android/content/res/Resources.html – Christine Nov 05 '16 at 15:37

1 Answers1

1

It will work fine for you

(your activity context).this.getResources().getString(R.string.final_ip);

or just simple in activity

getResources().getString(R.string.final_ip);
Hanzala
  • 1,965
  • 1
  • 16
  • 43