I'm thinking about possibility to put into AndroidManifest.xml some custom data. E.g. version of SQLite database for this particular release of app.
For sure i can put those data as hardcoded in sources or somewhere in preferences, but still I'm just wondering is it possible?
Why not put it in a res/values xml file (maybe res/values/strings.xml) as a constant?
Related
I developed an application and I want to create an update package which contains string.xml and styles.xml but no activity (just updated files, not the whole app package), Actually I tried this with same package name but it didn't work, Does android allow me to overwrite these files after installation? How can I do this?
Thanks a lot ...
The only way you can do that is by updating the existing code with the new styles and strings and updating the application from the distribution means that you have chosen.
Just food for thought :
If you have an application which have a constant change in the strings and styles, then perhaps you can create a dynamic application which fetches these settings from some server and applies these changes on runtime. It entirely depends what is the nature of your application.
I'm using in my Flashcards app strings.xml (value folder) as a database from where I extract the Questions & answers. Some colleagues told me that I'm miss-using string.xml!?
I really don't see any drawback using strings.xml as a database?
Do you agree with me regarding this point?
Do yo have better solution I mean better source code of a flashcards app to learn from it the best practices.
here is my code:
resId1=getApplicationContext().getResources().getIdentifier(
"textname" + 1, "string", getPackageName());
tex1=getResources().getString(resId1);
Many thank for your thoughts and assistance.
It is OK to use strings.xml as a read-only database, as long as you don't need to join data or do more advanced searches with it.
Using strings.xml is no different than using a text file as a "database" (I use that term lightly here).
You have to decide what's better for you here. Do you prefer to have a text file as a source of your data (which under certain circumstances can be completely viable) or do you need more control over your data (join, search, etc.).
If so, you can use the built in SqlLite to allow you to use an RDMBS but if not and you don't need to do anything other than having a read-only source of text, a text file approach is absolutely fine (even if it's in strings.xml).
I would suggest you to use Strings.xml as language file only, but if you think you don't have any confidential information's you are allowed to use Strings.xml as a database(but not recommended) however you can't store new values on runtime at Strings.xml.To handle some fewer data you can use SharedPreferences to store them and retrieve them, by (key, value) simple to use.
If u have large set of data then go for SQLite.
In my app I want to update the strings.xml file at runtime. So the idea is to download the content from an external API and then update the strings.xml file. Does anybody had any past working experience on this or any idea how to achieve this goal will be a great help!!
You cannot modify resources at runtime. You are welcome to ship a new APK that contains the new resources, though.
You are also welcome to download files from the Internet, parse them, and use their contents. However, you have no means of using them literally as string resources. They will just be strings (or whatever else you parse from the file).
You can't do that. If you ever happen to add values to the strings.xml at runtime, their ids won't be generated in the R.class, you can alternatively save those strings to another file on the phone (database file, json file, xml, etc.).
I'm new to android development and I was wondering if it is possible to change an XML file during runtime of the application.
I'm having an XML file with data that I put into a database, but I would like to have the possibility to download another XML-file (with newer data) and replace the old one.
(I'm not talking about the manifest.xml file or layout.xml files, it's a file I created myself in a self-made subfolder)
Any suggestions how I can manage this?
If you download XML, parse it in the database. Why do you need to 'replace' it? (You can do this but it's not the best solution).
What you should do is download the XML into memory (for example HttpClient or any other), parse the XML and directly insert into the database.
This means you don't need to save anything.
Facebook in their user guide suggest to keep a key in values/strings.xml file. Have never seen such an approach before and it sounds odd for me. Is it something everybody use? I always thought is it better to keep such a data in config files.
It is perfectly alright to keep data like this in strings.xml. Make sure you keep it in the default /res/values/strings.xml and not in any other values folder which has qualifiers attached to it. It may not be available on all devices if you do that.
Keeping this kind of data in config files is also perfectly acceptable (and the one I personally use, more because I find it easier to edit a Java file with static variables than an XML file in Eclipse).
Keeping the data in strings.xml means having an additional step in accessing it, as you'll need to get it from the resources using an instance of Context. Putting it as a static field in a Java class will make it slightly easier to access.
Both methods work fine, and are used commonly. It is really upto your personal preferences to pick one.