0

I am writing an application for android and i wish to be able to sync content from a web server, IE: The layouts XML to the device and cache it so that if the device is not connected to the internet it uses an old version of the XML so as soon as the device is on the internet is able to update and gather the latest XML.

Couldn't find much on the internet, so if someone could point me in the right direction or give me some ideas this would be quite helpful.

Cheers, Alex

1 Answers1

0

This is how it works with a normal xml file:

  1. Create an on your device HTTP Client
  2. Prepare a GET request to your server
  3. Send the request and retrieve the HTTP Response
  4. Read the content using an InputStreamReader
  5. Write the Stream to a file on the external storage name it e.g. newes_version.xml
  6. catch all exception, and just use the file newest_version.xml file.

But it can't work for Layout files

Why? Every time you load your app on an device, everything (except /raw) in the /res folder is being compiled. Therefore your 'stylsheets' doesn't exist anymore the way they did in your IDE. It's not as simple as in html/css where you can just exchange on file. (Well, you can, put not an runtime)

Solution

If you really want to change your layout on Run time, you would have to load the xml (see above), parse it, and apply the information given by file using the R.id reference of the View elements.

Community
  • 1
  • 1
Johannes Staehlin
  • 3,680
  • 7
  • 36
  • 50
  • Thanks, I'll take a look into it, Its basicly a guide app and i'd like to be able to add additional guides or change guides over time so thats why i'd like it to sync wit ha server. –  Mar 10 '12 at 19:20