avmauricio
avmauricio

Reputation: 1008

How to manage an application settings on Android

I'm working on my first Android application that sends many requests to a server (API) to load data, so I was thinking to use a separate file, like .plist on iOS, that will have a list of URLs (the app will read this file and this file will setup before the app runs for the first time), so on that way if I need to change any URL it will be easier and the app will get the change. I read something about "SharedPreferences" but I understand that I can only can save data when the app is running (no before).

My question is: what is the recommended way to do this? Android have a native solution for this scenario (something like application settings files)? can I setup a "sharedPreferences" file before the app runs?

Thank you very much,

Upvotes: 3

Views: 233

Answers (1)

Phate
Phate

Reputation: 6612

Create a urlList.xml file under res/values : this is your list:

<?xml version="1.0" encoding="utf-8"?>
 <resources>
<string-array name="my_urls">
    <item>url1</item>
    <item>url2</item>
</string-array>
</resources>

To access it from code:

String[] urls = getResources().getStringArray(R.array.my_urls);

Upvotes: 1

Related Questions