At some point, you may need to turn your online apps into offline apps to get the benefits of an offline application.
GeneXus has useful features to handle this conversion quickly. Converting an online application into an offline one is as simple as changing a property value in your application's main object. In addition, it is also available for you to manage several behaviors of your offline applications such as synchronization mechanisms, data storage in the device, and many others.
The first thing you should do is to change the Connectivity Support property of the main object to Offline. Next, you have to do a "Rebuild All" of the main object.
You can learn more about this property in the article HowTo: Use the Connectivity Support property.
When GeneXus has finished building, your offline application is completed and ready to be installed on your device. Read Offline Native Mobile Applications Requirements for more details.
You can also change many behaviors as desired.
Choose your preferred way of receiving data from the server by changing these properties:
Data Receive Criteria property: Choose when to receive the data from the server.
Data Receive Granularity property: Choose how to handle the changes to be synchronized.
Choose your preferred way of sending data from the device to the server by changing the Send Changes property.
Choose which tables of your system should be in your offline application. Read the article Offline Database Object Table selection to learn more.
Indicate which data the application stores in its offline database. Read the article Offline Database Object conditions for more details.
To use the GeneXus synchronization programs to send the changes made in the device to the server, the use of Business Components is necessary.
The application sends in the synchronization process only Insertions, Deletions, and Updates made by using Business Components. For this reason, it's important that you exclude the New, Delete, and ForEach commands from your objects for inserting, deleting, and updating data. Otherwise, the Warning spc0203 message will be shown during the Program Specification.
If you choose not to use the GeneXus synchronization programs, you can code your own Data Synchronization programs to send changes to the server.
At first sight, they may look the same, but they are different. The main difference is that WebSession data is lost every time the application closes, while the ClientStorage API stores the information to have the same information even if the application launches again.
Even if you have selected manual or automatic synchronization for receiving or sending data, the Synchronization API is always available, so that you can call the synchronization programs as needed. Read HowTo: Use the Synchronization API for further information.
Every time you use Business Components for Inserting, Deleting, or Updating data in your device, those actions, also called events, are stored in an auxiliary table inside the application in order to send the same changes to the server later. You can manage those stored actions with the SynchronizationEventsAPI external object. For instance, you can change the actions' status if something goes wrong in the synchronization process or remove some of the actions if needed.
It is possible to have preloaded data in your application when installed on the device. For more information, read HowTo: Create offline mobile applications with a preloaded database.
There are some non-implemented DataTypes for offline applications, yet. Moreover, the specification error "spc0106" occurs for offline objects that use those DataTypes. So it is easy to know which are the non-implemented DataTypes for each platform.
Here is the list of non-implemented DataTypes for offline applications for each platform: Offline non-implemented DataTypes
It is recommended to avoid the use of those DataTypes in Objects for Native Mobile applications development and use them in Server-only Procedures or Data Providers instead.
Sometimes you may have Procedure objects or Data Provider objects which execute only on the server-side. For instance, Procedures that use components not implemented for mobile platforms yet -like PDF reports, Excel files, among others-, some Procedures that need high computational power, or some Data Providers that use files located in the server file system. However, because of the Offline Native Mobile applications architecture, if an offline object calls some of these objects, they are going to be called offline and errors may occur while specifying or compiling the client-side application.
To run these objects online, a possible but more intricate option is to call them via the HttpClient data type. However, the Connectivity Support property gives an easier solution for this problem: by setting this property to Online on Procedures, Data Providers or Business Components, whenever you call these objects from an Offline Mobile object, the application calls these objects via REST services automatically. Another important fact is that these objects are generated only for the server-side application, avoiding many possible compilation errors from the client-side application.
In the same way there might be some Procedures or Data Providers which have to be executed only on the server-side, there might also exist some Procedures or Data Providers which are only executable in the client-side. That means, these objects should be executed only by the device. This is very common in, for example, Procedures that uses External objects which are defined only for Mobile platforms. However, because of the Offline Native Mobile applications architecture, if an offline object calls some of these objects, by default, these objects are generated for both client-side and server-side applications. So errors may occur while specifying or compiling the server-side application.
To avoid generating those objects for the server-side application, first, be sure that the objects are not called by any Web object, and secondly, set the Connectivity Support property of each Procedure or Data Provider to "Offline".
GeneXus Access Manager (GAM) is available for Offline Native Mobile applications. Despite this, it has some restrictions that you should consider when converting your application from Online to Offline. For more details about this topic, read Offline Native Mobile applications using GAM.
Read Offline Native Mobile Applications Common Issues if you are having any trouble.
Offline Native Mobile applications architecture
The Data Synchronization Problem
Offline Database object