-2

I need some advices about good practices of importing data from server to local device. The amount of data is not very big ~1-3 MB So, I have to choose between:

  1. receive json - parsing it, using GSON lib for simplicity and insert data into local DB
  2. receive whole DB in cvs format and then to populate my DB like is described here
  3. or receive the whole DB directly from server side and use it somehow like local one

I know, each method works but if somebody can give some arguments it will be appreciated.

Community
  • 1
  • 1
johny
  • 187
  • 1
  • 1
  • 11

3 Answers3

0

You can provide an already populated db with your app ( put it in your asset folder ).

Then all you have to do is keeping up to date the fields you have to update on the app using a timestamp field or any sql request to find the outdated fields or the entry which are not present in your db.

This way you avoid useless process in you app to populate the db, and you can limit the query to your server aiming the data after s specific time, this time being the last update of the database.

Virthuss
  • 3,142
  • 1
  • 21
  • 39
  • When opting for this approach you might want to check SQLiteAssetHelper by Jeff Gilfelt. I wrote a small tutorial about it: http://www.6020peaks.com/2015/03/how-to-ship-an-android-app-with-preloaded-data/ If the data in your app and in your server can be modified separately, you will need to write some kind of data synchronization logic. – narko Oct 02 '15 at 08:42
0

what worked for me was my php file was reading data from sql ...

so I used buffer reader to read content on those file its fast and easy

worked for me

public String getInternetData() throws Exception{

        BufferedReader in=null;
        String data=null;
        try{
            HttpClient client=new DefaultHttpClient();
            URI website=new URI("http://address of that paticular page.php");
            HttpGet request=new HttpGet();

            request.setURI(website);

            HttpResponse response=client.execute(request);
            HttpEntity ent=response.getEntity();
            String dt=EntityUtils.toString(ent);


            data=dt;
            //in=new BufferedReader(new InputStreamReader(response.getEntity().getContent()));


        }catch(Exception e){


        }

        return data; 
Sumeet Masih
  • 597
  • 1
  • 8
  • 22
0

tl;dr;

I will keep the first solution.

Arguments

Solution 1

JSON is a standard ! You can use any library that you want and even change from to another if you have any problem ! Moreover, JSON is a lightweight format.

Also, transferring the data this way, you will be able to store as you want : with the same scheme or with another one; you will be able to remove useless data, ...

The only problem : you cannot validate that the data you received are like you think. You will have to handle the verification on your mobile.

Solution 2

I think that this solution is just the same that with the JSON one, but using a really ugly format... I will definitely not use it !

Solution 3

You will send a binary file through the network. If something bad happened, you will not be able to know it before trying to open the DB and see that it fails.

Moreover, you are stuck with the DB scheme that your server decides. I think it's way better to let your device handle the DB scheme by itself. The server is responsible to transfer correctly formatted data. Then, your device is responsible to store them the way it wants.

mithrop
  • 3,283
  • 2
  • 21
  • 40