1

I'm developing an android application that needs to connect to a remote server. A lot of classes (actually activity) need to connect to the same server, but through different RESTful web services. Instead of have the address of the server (or http url) hardcoded in each of those classes, is there any option of having a light properties file (xml if possible) that can indicate such information (so if the url/ip change, I just have to modify this file and not the whole source code) and how can I manage this file? FYI: I use httpclient (http://loopj.com/android-async-http/).

Albert
  • 10,377
  • 4
  • 22
  • 27
Cromm
  • 328
  • 6
  • 25
  • See this: http://developer.android.com/guide/topics/data/data-storage.html#pref The Developer Guides are a rich knowledgebase especially for beginners (but not only for them). – Fildor Nov 25 '15 at 15:24

1 Answers1

0

You can use SharedPreferences interface for this. See Android SharedPreferences doc to understand it.

From Android doc:

The SharedPreferences class provides a general framework that allows you to save and retrieve persistent key-value pairs of primitive data types. You can use SharedPreferences to save any primitive data: booleans, floats, ints, longs, and strings. This data will persist across user sessions (even if your application is killed).

You may follow How to use SharedPreferences in Android to store, fetch and edit values and sharedpreferences tutorial for examples on how to use it.

Community
  • 1
  • 1
cgr
  • 4,578
  • 2
  • 28
  • 52