In this tutorial we are going to build a Hello World Android app and deploy/test the app on Android device. .
Creating New Project
- To start, we are going to create a new app. From Apps tab, click Start Now button
- Under App Builder, click Go
- Under Mobile App, click Start Now
- Select Blank Mobile App app and click Next Step button
- Enter AndroidHello for app name and click Create.
- Once the app builder editor is loaded, you will see the following:
Now that we got the project, we are ready to build the UI.
Building the UI
- Find the Input component and drag and drop it into the phone. Delete its default Input label.
- Find the Button component and drag and drop into the phone. Change the button label to Hello Android.
- Double click on Caption label and change it to Android Hello World, for example.
- Select the screen (you can click outside the phone) and in Properties, pick one of the available themes. We are going to use Blue.
- Once you completed all the steps, the result will look like this:
- Before we build a second page, let's make a few minor updates. First, select the screen again and in Properties changes its name to Start. Then, select the Input component and change its name to input (in Properties). We are going to refer to these elements in just a few steps and giving them names will make it simpler for us to find them.
- Switch to Projects view, then select Create New > Screen.
- With Mobile screen template selected, click OK to create a new screen
- In Properties, rename the screen to Hello. Then, change its Theme to Blue to match the first screen.
- Change its label to Hello, for example.
- Switch to Palette view
- From the Mobile palette, drag and drop Grid component. The Grid component has 2 columns by default.
- Select Label component and drag and drop it into the first grid column.
- Change its label to Hello.
- Then, drag and drop another Label component into the second grid column. Delete its default label.
- Lastly, change the Label component name to enteredName. Once you are done, your screen should look like this:
Setting Up Variables, Events and Navigation
- Open Start screen
- Open the Events view (right-hand side) and select the button component.
- Select Add Event > Click. Click event will be listed in the box below.
- Click the + button on the right and add Set Local Storage Variable action and set the following values:
- Variable name: name
- Check: Bind to component
- Target component: input
- Property name: Text
- Click OK
When the button is clicked, the value entered into the input field will be saved in local storage.
- Under the same event (Click), press the + button on the right and select Navigate to Page action
- Select Hello page and click OK
- Open Hello screen
- Select the screen, then Events > Add Event > Load.
- Click the + button on the right and add Set Property action and set the following values
- Component name: nameEntered
- Property name: Text
- Check: Read from local storage variable
- Variable: name
- Click OK
On screen load we are reading the value we saved into local storage on previous screen.
Testing the App
You may now test the app. Open Start page and click Test. A new browser window will open where you can try the app. Learn more about Testing Your App.
One More UI Update
Let's make it easy to go back to our first page from the second.
- Open Hello page
- Drag and drop a Button component and place it in the header, on the left side of the label
- Change the button label to Back. It should look like this:
- Click the button, then Events > Add Event > Click.
- Click + and add Navigate to Page action.
- Select Start page, click OK.
- You may test the app again.
Testing the App on Android Device with Tiggr Mobile Tester App
Install Tiggr Mobile Test app on your device. From this app, you can launch and test any app in your account. What you will run is a native app. You can install Tiggr Mobile Tester from here. We recommend this approach as this is the easiest way to test and app without having to update and install it each time.
Once Tiggr Mobile Tester is installed, login with your username/password. You will see a list of all mobile projects. Click the project, click Preview and after a few seconds, the app will launch. Tiggr Mobile Tester look like this:
Exporting and Publishing the App
Once you tested the app, you can generate Android binary file install it on your phone or publish it to Android Market.
To export as Android binary, select Export button from the top menu. You will see the following window:
There are two options for Android binary:
- Debug binary - this app cannot be published into the Android App Market and can only be installed on your phone.
- Release binary - this app can be instantly published to the Android App Market.
- Optionally, learn more about setting Android APK properties. This step is not required to generate a binary file, all default values will be used otherwise.
If you decide to just test the app directly on your phone, one approach is to email the app to your phone. When the email is downloaded, your Android device will recognize that it's an app and offer you to install it (by clicking a button).
Getting Native, Really.
You have just built (your first) real Android app. Still hesitant? Let's add some native code with PhoneGap API.
- Add a button on the Hello page, change its label A Fun Button.
- Select the button, then Events > Add Event > Click.
- Add Run Custom JavaScript action. Enter the following JavaScript:
alert('Device name: '+ device.name+'\nPhoneGap: '+device.phonegap+'\n
Platform: '+device.platform+'\nVersion: '+device.version);
- Run the app again on your Android device form Tiggr Mobile Tester.
Note: because JavaScript calls native API, this will not work in browser. You can learn more about PhoneGap device API here.
|
|