My first Android application

This document is a step-by-step explanation of how to create a simple Android application with GeneXus using Ruby and SQLServer. If you are using another generator (.NET, 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 Ruby as Prototyping Language (you can use .NET Generator or Java Generator).

SD Creating KB

 

Step 2

Create a Customer and Company transaction with the following structure:

Android GX Step 2

Note the Domains with Special Semantics in Phone, Email, Address attributes. In both cases use autonumber in the identifier attribute. While positioned in the CustomerId field, press F4 to see its properties, and 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. For example, 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

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

SD dragging attributes to layout

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

SD No label caption for an attribute

 

Step 4

Create a Dashboard object called, for example, Menu. 

Creating a Dashboard from New Object Window

This object is like a menu; you can use it to call the Work With objects created in the previous Step. To do so, right-click on the Items option to add actions to the dashboard. Add an action for each Work With. You must select the WorkWithDevicesCustomer in the Select Object dialog that displays them for the first work with, and do the same for the second one, choosing WorkWithDevicesCompany:

SD Getting Started Dashboard

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 (default)
  • Generate BlackBerry: False
  • Generate iOS: False
  • Main Platform: Android
  • 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

 

Step 6

Press F5 to build the application. The first time you do it, GeneXus needs to know the database connection information. This may help too: First Ruby Model

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 your default web browser and the Android Emulator:

SD GettingStarted Ouput

so you are ready to test both applications (web and SD).

Step 7

Through the Development Menu opened in your browser, insert some companies and customers (in that order):

Inserting via DevMenu Web

Now, wait until the Android emulator starts running the application. The first time it may take longer because the emulator Starts the Android OS:

SD Android Emulator Launched

After that, the application starts:

SD GettingStarted URL

And you can test it! 

Step 8

To easily run your application directly on your Android device, see Executing From QR Codes

Enjoy it!

 

Some Pics

SD GettingStarted Some Pictures

Note: To display an image for each menu action, go to the corresponding dashboard object created in step 4. Next, positioned on each action, associate the image (inserting 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.
  • This link is another tutorial with some additional help for troubleshooting (Spanish only).

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