What better way to create an app that works offline and synchronize data with the server? [closed]

11

I'm digging into the Mobile world, where I had the first challenge, which is to create an Android App for basic registration, name, age, etc. The complicated (at least for me) is that I have to update this data saved in SQLite from Android to a MySQL DB on the server.

I'm using the RAD Studio XE8 tool.

Would anyone have a light on how I do this? Do I have to enable some service from outside, or leave a Windows application running to do the integration? My goal is to simply realize that when you click on a sync button, the record is saved to the server DB, and another button to clear the data.

Thank you.

    
asked by anonymous 20.05.2015 / 23:27

3 answers

4

The method I suggest is as follows. Assuming you can use a scripting language on your server, first load Local Bank data into the Delphi (Android) application.

To proceed, add the Indy HTTP library and System Classes:

uses Classes, IdHTTP;

Create the required variables:

var 
    ParamList : TStringList; // Lista para representar o registro do banco
    MyRow     : TWhatever; // Esta variável hipotética representa o objeto ou array onde você terá o registro do Banco Local
    HTTP      : TIdHTTP; // Objeto HTTP do Indy

Put the data to be passed to the server (single table record) in TStringList in the default format of URIs:

ParamList.Add('id=' + MyRow.ID);
ParamList.Add('name=' + MyRow.Nome);
ParamList.Add('phone_number=' + MyRow.PhoneNumber);
// Adicione todos os campos da tabela.

Next, you must create the Indy HTTP object and perform the POST to the Script on the server:

HTTP := TIdHTTP.Create(nil);
try
    HTTP.Post('http://ip-ou-nome-do-servidor/pasta/do/script', ParamList);
finally
    HTTP.Free;
    ParamList.Free;
end;

The above example would send the First Name, Last Name, and ID data to a script on the server (possibly in PHP or another language you prefer, know or want to learn). This script in turn would perform operations on the Remote Bank (Server).

This is clearly just a generic and illustrative example. Contains the base concepts for the method.

If you are not aware of any of the above terms, I suggest you study:

  • HTTP
  • POST and GET
  • CGI scripts
22.05.2015 / 19:10
0

You could use the DataSnap REST technology with Embarcadero's own JSON object, which makes the synchronizations between Client / Server making the response time much faster and the FireDac component to make connection to the database for Mobile Android and MySQL, the technology is ready to work in offline mode so it would not stay all the time online, only when synchronizing. If you are not aware of this new technology I suggest you take a look at the tutorial that Adriano Santos did.

TDevRocks DataSnap REST

    
30.10.2015 / 14:58
0

In fact, what is difficult in your question is more in relation to the many forms that Delphi allows you to make, that choosing the best one actually depends on each particularity.

For example, in delphi it is very simple to connect to DataSnap and has a lot of tutorials in YOUTUBE teaching you to implement both the server side and the client side. From one studied in JSON which, in my opinion, is the best way out for sending information to the server. To retrieve the information, trust the DatasetProvider -> ClientDataset

Firedac also has a number of new features, such as ETL components, which allow you to synchronize different database tables, and a fat feature that may be enough for you: Work with the offline bank.

I recommend the DEVMEDIA courses, especially by Professor Guinter Pauling, a specialist in these subjects.

If you have a REST server to consume, then Delphi also has excellent connection controls, and I recommend starting with restDebuger, which comes with delphi.

    
25.01.2017 / 04:58