How to mount a WebService to synchronize SQLite database of Android and MySQL

5

I've set up an android app that stores basic information about a contact in SQLite:

asked by anonymous 18.08.2015 / 03:16

1 answer

6

You can use the combination JSON API + Retrofit . Explaining a little:

  • You must create a data pattern so that both your application and your remote database can "understand" the information that is shared between them. This pattern can be created using JSON, since both PHP and Android can read JSON files (using their proper libraries);

  • You should create a JSON API, which will be the communication standard between your application and your remote database, that is, you must create a communication "language" that PHP and Android will use to request and send data to each other;

  • In PHP, it is very simple to read and send data in JSON, but on Android you will need a library that reads and sends JSON data from a remote database. This library can be Retrofit.

A small example:

  • Data pattern : Suppose client data is represented this way in JSON

    {
        "cliente": {
            "nome": "joao",
            "email": "emaildojoao",
            "endereco": "enderecodojoao"
        }
    }
    
  • JSON API : Now suppose you have created a clients page on your site and every time it was accessed it would return a JSON array with all the clusters of your database, so every time the application wanted to access the client list of the remote database, it would need to access the "/ yourite / clients" link.

  • Using Retrofit : In your application, using Retrofit, you could write the following code so that your application could pick up the client list from the site

    @GET("/users/list")
    List<Cliente> listaDeClientes();
    

    In this case, when you call the listaDeClientes() function, it automatically returns a list of Cliente s from your site.

Remembering that this is just one of many solutions. If you are interested in this one, take a closer look and when you have more specific doubts, just come back here.

    
18.08.2015 / 03:53