Recents

My first Android applicationOfficial Content

This document is a step-by-step explanation of how to create a simple Android application with GeneXus using .NET  and SQLServer. If you are using another generator (Java) or DBMS, the steps are the same even though the prerequisites change.

Before starting the following steps, please check that the Android Requirements are correctly installed. See Android Smart Devices for more information.


After following this step-by-step guide, the following application should be obtained:

Then, it can be improved for a great look & feel.


 

Step 1#

Create a New - Knowledge Base and select C# as Prototyping Language (you can select also Java).

SD Creating KB - GeneXus 15

 

Step 2#

Create a Customer and Company transactions with the following structures:

Android GX Step 2

Note the Domains with Special Semantics in Phone, Email, Address attributes.

Let's autonumber the identifier attributes. While positioned in the CustomerId field, press F4 to see its properties. Then, change the Autonumber property to True. Do the same for the CountryId attribute.

Step 3#

Apply Work With for Smart Devices pattern to both transactions. To do so, open each transaction, click on the Patterns selector, choose the Work With for Smart Devices tab, and select the checkbox as shown below. Next, click on Save:

SD Applying WW to Customer - GeneXus 15

From the Toolbox, drag & drop the control Attribute/variable to insert the attributes you want to see on the Customer list screen (i.e. CustomerEmail):

SD dragging attributes to layout - GeneXus 15

To remove the attribute label, change the Label position property value to "None":

SD No label caption for an attribute - GeneXus 15

 

Step 4#

Create a Menu for Smart Devices object called, for example, Menu. 

Creating a Dashboard from New Object Window

This object is like a menu; you can use it to add items/actions to it, in order to call the Work With objects created in the previous Step. To do so, right-click on the Items option and add two actions consecutively to the dashboard. Each action must be associated to each Work With. You will be able to select the WorkWithDevicesCustomer in the Select Object dialog for the first action and the WorkWithDevicesCompany for the second action:

SD Getting Started Dashboard - GeneXus 15

When you select a WorkWithDevices <TransactionName> object, the Event associated with this action will be generated automatically:

Event 'WorkWithDevicesCustomer'
     WorkWithDevicesCustomer.Customer.List()
EndEvent

Event 'WorkWithDevicesCompany'
     WorkWithDevicesCompany.Company.List()
EndEvent

 

Step 5#

Edit the SmartDevices Generator Preferences. Make sure you have set the following properties:

  • Generate Android: True
  • Main Platform: Android (default)
  • Android SDK directory: Select your Android SDK directory (that is: the directory where you have installed the program) 
  • JDK Directory: Select your JDK directory.

My First Android Application Preferences - GeneXus 15

With this settings, the Android and iOS code will be generated, and in runtime the Android platform application will be executed.
 

Step 6#

Before pressing F5 in order to build and run the application, the developer has to Set as Startup Object a Main SD object. Dashboards by default are Main (their Main Object property is set to True by default), so let's set the Menu Dashboard as Startup Object:

My first Android application - Set As Startup Object

Next, press F5. The first time you do it, GeneXus needs to know the database connection information. 

SD GettingStarted Set Build Proccess

The other possibility is to deploy to cloud.

The following output is shown, as well as the Impact Analysis report, indicating the tables that must be created in the database. Click on the Create button to create them. 

SD Impact Analysis Report

Then, GeneXus automatically runs the Android Emulator:

SD GettingStarted Ouput - GeneXus 15

so you are ready to test it!

Let's tap on the Work With Devices Customer option. The following screen will be displayed:

WorkWithCustomerAndroidEmulator

Use the highlighted button to insert some customers.  

Continue testing the application by updating data, deleting, adding companies, etc.

Some Pics#

SD GettingStarted Some Pictures

Enjoy it!


Note 

To display a desired image for each menu action, go to the dashboard object created in step 4. Then, being positioned on each action, associate the image (inserting it simultaneously in the KB) through the properties dialog:

Image Dashboard Action Property
 

Tips#

  • To simplify the prototyping process, we recommend not to close the emulator between runs.
     

Download the XPZ#

To import GeneXus objects used in this demo, right on your KB, download the following file:  My First Android Model

For more information, read Android - FAQ and Common Issues


See also

Was this page helpful?
What Is This?
Your feedback about this content is important. Let us know what you think.