简体   繁体   中英

Best way to get remote data that changes a lot

There are 3+ apps which collect parameters in the form of one string, like "Peter", "Jane", "Mary", etc. At the moment I keep this parameters in String[] array. However, the data needs to be changed a lot so every few days I have to amend strings, recompile APKs and publish it. Just waist of time.

What should be the simplest way to keep this data in a remote file (NOT database), maybe text file, so that the apps can download list of parameters on need? My idea is to change this file just once, upload it to some remote server and then the apps download parameters automatically. This way I would not have to recompile and republish the APKs.

If the text file is the simplest solution, what should be the form of it? For example, should I write parameters like this

Peter, Jane, Mary, ...

Or in some other form?

Is there a need for some layer between this text file and Android app, like when we make layer on the remote server to grab data from database? Or I can simply grab data directly from this remote text file?!

Well the delivery mechanism could be a simple HTTP GET your app performs to a web server you control. It could be as simple as http://myhost/names.txt .

The data format depends on what you want to do. The super simple solution would be a text file with a different name on each line:

Peter
Jane
Mary

Or, you could serve up JSON from the server and parse it on your client.

{ "names": [ "Peter", "Jane", "Mary" ] }

The JSON solution would be more extendable, should you wish to add more values in future, eg:

{ "names": [ "Peter", "Jane", "Mary" ], 
  "lastnames": [ "Smith", "Johnston", "Cumberbatch" ] }

Really depends entirely on what you're comfortable with and what your situation calls for.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM