0

I want to give backup facility in my android application. So for that purpose i don't know which which format will be suitable. I am thinking either XML or CSV. Please tell me which is efficient.

Kaustubh Khare
  • 3,280
  • 2
  • 32
  • 48

2 Answers2

1

It's my opinion that you're probably better off using JSON, as it has many great advantages as listed below and given your data, wont be considerably larger than CSV or Binary. Take a look at this post for details on how to implement it:

How to parse JSON in Android

The following is a general breakdown of the different data format options:

XML This format is the least efficient (file size and time to parse), but comes with the advantage that it can be easily debugged or modified/read by a person. In general, use this if you are going to be reading the content, displaying it in some other program or the file will be small enough that it's size and processing disadvantages don't have a significant effect.

JSON More concise than XML, while still maintaining it's human readability. It's syntax isn't quite as simple as XML but it's still very simple. I would recommend this over XML.

CSV This format is much more efficient than XML, but is prone to errors if modified manually and can be very hard to read. You will likely require special care in dealing with the delimiting character so you'll want to find yourself a simple CSV library. It's disadvantages are that although

Binary These formats will be read/written to a file as bytes. They are structured in such a way that only your specific application/reader will know how how the bytes are structured. This format is the most concise and has the best read/write performance, but of course, it's practically impossible to modify or read.

Edit: Also worth considering is your ability to modify the format of the data, for the purposes of supporting future version changes. Using JSON or XML allows you to easily add new fields or ignore existing ones and so can be easier to maintain backwards compatibility for existing applications without breaking their functionality. A similar solution for CSV or Binary would require that you store and check the data format version number with the files, and then manually switch between loaders in code.

Community
  • 1
  • 1
TheIT
  • 11,919
  • 4
  • 64
  • 56
  • customer information like name, phone number, transaction type and amount which is stored in SQLite. I want to provide backup/restore facility to my application. If user accidentally uninstall app then he/she could restore that data and used it. – Kaustubh Khare Jan 11 '14 at 06:48
  • @KaustubhKhare I just updated my answer. I hope it helps you make an informed decision. Don't forget to mark the answer as 'accepted' if it answered your question. All the best! – TheIT Jan 12 '14 at 02:42
1

I'd go (and I use them in my apps) for CSV files, since the data are crude and concise (i.e.: small file size and fast to read/write).
I won't choose XML files, which put a lot of garbage in the file, bloating them ridicolously.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115