I have looked for a solution, but getting solutions for SharedPreferences and SQLite databases. I have to store a single URL that my Android application will access for getting some data. I like to keep that as configurable, as in case I can change the URL and use the app with another set of data.
If I use strings.xml, will I need to repeat the same in case I am adding support for other languages?
For storing in SharedPreferences, I need to store it somewhere till the app is installed to be able to save it there.
Using an SQLite database for this seems too far fetched?
I think the basic thing would be to store it in a Constants class, but I am not sure whether that is the correct approach.
Can someone suggest a better solution?
You don't indicate that the url should remain private. So, you may be overlooking the obvious. Why not simply create a "configuration" file that is installed with the application? This can be achieved by following the methodology here. Once it is installed, your application can simple read it and process accordingly.
In our app we store all static configuration in the AndroidManifest.xml as meta-data properties.
The link to the docs can explain it better than I can:
http://developer.android.com/guide/topics/manifest/meta-data-element.html
Basically:
<meta-data android:name="api.url" android:value="http://api.some-api.com"/>
Then assuming the meta-data is at application level, you can get it using:
Bundle data = context.getPackageManager().getApplicationInfo(
context.getPackageName(),
PackageManager.GET_META_DATA).metaData;
String apiUrl = data.getString("api.url");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With