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.
Related
I got a thing to think about, but cannot find the solution. New layout file is being received from the server.
I faced problem that Parser cannot resolve all those android attributes to inflate view in the next step. We can change file format on server-side to make it as attributes, but how to parse it and set properly still a question.
Does anybody have any idea or suggestions how to do that? Thanks in advance.
You can't. Two problems.
1)You can't parse a general xml file and make a layout from it. From the docs on LayoutInflater.inflate() "Important For performance reasons, view inflation relies heavily on pre-processing of XML files that is done at build time. Therefore, it is not currently possible to use LayoutInflater with an XmlPullParser over a plain XML file at runtime."
2)You can't save to assets. Assets are read only. Of course you could use the filesystem instead.
You can get what you want, but you'd have to write your own parser for your layout files from scratch. Its highly not recommended.
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 want to implement an application which will work as a parser. User will be able to upload xml files which will describe UI and functional properties of some android application. I wonder if there is already a way to parse xml files and use them as layouts without compiling?
I think that you're parser will have to generate new Views which receive "parameters" via the xml files. Afterwards you'd have to add the Views progammatically to your layout root.
It doesn't really matter which parser technology you are using for this purpose as you're going to create objects from it - so SAX, DOM & Pull-Parser would all be suitable.
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?
I want to load a single XML file of 1.2Mb in android through assets folder as raw file. I heard that there is a limitation in android of 1Mb for a single xml file. How can I get rid of it? Is there any option to overcome this issue?
First, don't use assets/ for XML, if your intention is to use it in your application. Use res/xml/, as parsing will be about ten times faster, and will also take up less space.
Then, I would simply try it with your file and see if it blows up. I know there is a limit, but I do not know what the threshold size is.
If it blows up, you will either need to split it into multiple files (each with a subset of your data), or not package it with the application, instead downloading it from a server on first run of your appl.