LiveCode LessonsHow To - LiveCode Mobile Tasks Getting Started with AndroidThe Basics: How do I Create Hello World on Android?

The Basics: How do I Create Hello World on Android?

This lesson describes the very basic steps of creating an application that runs on Android via LiveCode. Screen captures and sample code are provided.

Introduction

The lesson bridges the gap between installing the Android development environment (covered in lessons: How do I Become an Android Developer on a Mac? and How do I Become an Android Developer on a PC?) and implementing the first LiveCode application that runs on an Android device. The code is very elementary and the steps are very detailed, focusing primarily on the mechanics of implementation and deployment.

Note: This lesson assumes that you have already installed and configured the necessary packages to begin developing software for the Android platform.

Open LiveCode and Create a new Mainstack

Open LiveCode and Create a new Mainstack

Open the LiveCode IDE and create a new mainstack by selecting File -> New Mainstack from the IDE panel. This creates an empty stack on which you will be implementing the application.

Create a Button

Create a Button

Drag a button (1) from the IDE Tools onto the new mainstack (2).

Change the Name of the Mainstack

Change the Name of the Mainstack

Right click on the mainstack window you created to open a dialog window, then select Stack Property Inspector from that dialog. Change the contents of the Name field from Untitled 1 to Hello World.

Change the Name of the Button

Change the Name of the Button

Select the button you just dropped onto the mainstack window and the Property Inspector changes to display the properties of the button. Change the Name of the button from Button to Click Me.

Write the Code

Write the Code

Right click on the button you just renamed and select Edit Script. The Script Editor window opens, allowing you to write the code that is to run on your Android application. Add the following code into the editor window:

on mouseUp

answer "Hello World!" with "Ok"

end mouseUp

Then select the Apply button. You have now implemented your Android application and are ready to launch it on an Android device.

Launch the Android Device Emulator or Connect a Physical Device

In this lesson we are using the emulator to simulate an Android device. Launch the Android emulator from your Android SDK and AVD Manager.  Lessons: How do I Become an Android Developer on a Mac? and How do I Become an Android Developer on a PC? would have shown you how to configure and start your simulated Android device.

Note: The emulator needs to be running for LiveCode to launch your application.

Configure the Standalone Application Settings

Configure the Standalone Application Settings

Select File -> Standalone Application Settings ... from the IDE Panel. This launches the Standalone Application Settings dialog. Select Android as your target and ensure that the Build for Android tick box is selected. You should be able to use the default settings.

Select the Target and Launch

Select the Target and Launch

The last step is to select the deployment target from Deployment -> Test Target. You should be able to select the emulator that is already running. This enables the Test button that launches your application into the Android emulator.

Running the Hello World Application

Running the Hello World Application

Once the application has been launched and is running in the emulator, you can interact with your application. Try selecting the Click Me button to raise the dialog. Then select the Ok button to dismiss the dialog again.

22 Comments

doug

so i went to development->plugins->and there is no revandriodplugin !!!!
so what now .. i want to see this thing run...

Elanor Buchanan

Hi Doug

Android deployment has now been integrated and the plugin is no longer required. This lesson has now been updated to show the new process for building and deploying to Android devices.

I hope that helps.

Elanor

ArchiMark

Excellent!

Got the example app up and running on the emulator...

Thanks!

Mark

stacy

what am i missing.. can't select "test target"

valdemar

Hi,

I have downloaded the trial of livecode platform, i cannot test my application since test button is inactive on toolbar. Is it because of trial version or something else?

Thanks.

Elanor Buchanan

Hi

If the Test or Test Target options are disabled the first thing to check is that you have the Android SDK installed and set up in your Preferences and that you have the emulator running.

There are lessons explaining how to set this up at

http://lessons.runrev.com/spaces/lessons/manuals/2571/lessons/27385-How-do-I-Become-an-Android-Developer-on-a-PC-

http://lessons.runrev.com/spaces/lessons/manuals/2571/lessons/27389-How-do-I-Become-an-Android-Developer-on-a-Mac-

You also need to have Android selected in the Standalone Application Settings.

I hope that helps.

Elanor

Tom

Hi,
1) I have setup Android sdk and Livecode and android 2.2 and 4.1 emulators and programmed the "Hello World" code per above. But, when I hit the Test Button in the top menu I get an eror message. is this because I have a 30-day trial version of LiveCode. Do I need the purchased /licensed version to run the emulator? Thanks

Hanson Schmidt-Cornelius

Hi Tom,

no, if you have an Android trial license and the license has not yet expired, then you should be able to test your application on the Android Simulator and Android Devices. It is more likely that you have an error somewhere else. I would recommend contacting support (support@runrev.com) with the details of the error message. They should be able to help you with the problem you are having.

Kind Regards

Hanson

Bill Moseley

I followed the steps, and when I test, the emulator launches an app (I think), but screen is just black - No button.

It also seems to be using a lot of CPU cycles.

Any idea what I might be missing?

Hanson Schmidt-Cornelius

Hi Bill,

it can take some time for the emulator to start up the first time, and the screen is initially black. This changes after a while, and you should see the text "Android" on the black screen. This changes again and after a while you should see a working Android interface with a default login screen. You should wait until you see the login screen and log in before you try to test something on the emulator.

Yes, the emulator is CPU intensive, especially during startup. Depending on the CPU and RAM, it can take several minutes.

Hope this helps.

Kind Regards,

Hanson

Rafal

Hi Hanson,

I have the same issue as Bill.
The emulator is already running and all ready (on home screen). I click "Test" and it builds etc. then installs on the emulator no problem. Then it executes it and I get the same - just black screen with no button.

I've tested it changing some of the settings, i.e. the screen orientation and showing/hiding the status bar - these two changes worked when tested again on the emulator, so it definitely installs and runs the Hello World app. But still just a black screen...
I tried on a phone with the right Android OS version and it fails to install. Doesn't tell me why though.

We've got a full license of LC 5.5 (upgrade purchased today to include Android deployment). Everything installed as it should be (in fact I use Eclipse and Java to develop for Android, we only use LiveCode for prototyping Web apps). So SDK etc. all up to scratch...

Thanks in advance,
R.

Rafal

Hi Bill,

I managed to resolve it (sort of).
It seems like something is not quite right, because it only works when I deploy it to a newer version of Android (either emulator or a physical device).
I've tested it on emulator running version 3.0 and also on an Asus Transformer also running 3.0 I think and then it works.
This shouldn't be the case, because the application is set to only require 2.2.

RunRev told me they managed to reproduce the issue and a bug has been raised.

Regards,
R.

Hanson Schmidt-Cornelius

Hi Bill and Rafal,

there appears to be a problem between revision 2 and 3 of the Android 2.2 SDK Platform. You can work around the problem for revision 3 by setting the Accelerometer, Magnetic field support and Orientation support to "no". You can do this when creating a new AVD or updating an existing AVD.

In the dialog "Edit Android Virtual Device (AVD)" do the following:

Next to the table with the label "Hardware" you should find a button called "New...". Click this button and select the mentioned hardware features, one at a time. Then select the value for each of the features and change it to "no".

Kind Regards,

Hanson

Saverio M.

Dear sirs, i have a problem with livecode 5.5 and the emulator, i have installed it on an imac i3 4 gb ram lion 10.7.3 i followed the steps you say..but the livecode tell me this "Unable to build app for testing: could not compile application class"
But the emulator is running and working ok. the livecode 5.5 recognize the virtual emulator android .i have installed that you need : android 2.2 ver 8 and sdk and jdk ok...Can you help me? please?? Best regards....

...Thank you a lot for your cooperation.....
Saverio M.
www.fasasoftware.com

Hanson Schmidt-Cornelius

Hi Saverio,

this error is most likely to be raised when you have an invalid Android Identifier.

Open your Android Standalone Application Settings for the application you are building and select the Android icon at the top of the screen.

Ensure that the content of field "Identifier" only has full stops and ASCII characters. This field should not contain white space such as tabs or spaces.

Kind Regards,

Hanson

shane

I had trouble testing the 'hello world' program on the android 2.2 froyo emulator...i figured out i needed to keep open the 'Standalone Application Settings' window, as I selected the deployment target and launched the test target.

happy days!

Hanson Schmidt-Cornelius

Hi Shane,

once you have made the selections you should be able to close the windows and LiveCode will remember what you selected. Can be a little bit fiddly to get everything communicating the first time, but once it is up and running, it should go quite smoothly.

Kind Regards,

Hanson

Jun

Hi Guys,

I am using livecode 5.5.5 and created the hello world app. When I select Development->test, it launches the application on the device but it displays black screen. My android version is 4.1.2

Thanks,
Jun

Hanson Schmidt-Cornelius

Hi Jun,

yes, the black screen issue was caused by a build issue. We have now fixed this problem. Try downloading our latest LiveCode 5.5.5 release. You can download it here: http://downloads.livecode.com/livecode/5_5_5/

Kind Regards,

Hanson

Jun

Thank you Hanson. I'll have to use the latest release.

By the way, I made a workaround on this one on my end which is currently working.

Here's what I did:

1. In Livecode 5.5.5, I renamed the folder "Android" to something different such as "Android1". This folder is located under Contents/Tools/Runtime.

2. In livecode 5.5.4, I copy the Android folder located under Contents/Tools/Runtime and paste it inside Livecode 5.5.5/Contents/Tools/Runtime

Note: I don't encounter black screen issue on Livecode 5.5.4

Thanks,
Jun

gary

Hi,

This is fine as far as it goes but I need to receive input from the keyboard on Android. Someone on the forums pointed me to the mobilecontrol functions, and I have seen the lesson "How do I use Native Text Controls on Mobile". However it is still not very clear to me how to go about doing this. Basically I want to know how to set up an input field so as to receive input which I can then go on to process.

Thanks,

Gary

Elanor Buchanan

Hi Gary

The best place to get this information is in the lesson you mention, but to simplify it somewhat you use

mobileControlCreate to create a text input control, then set its rect(area) and visiblilty eg

mobileControlCreate "input", "testinput"
mobileControlSet "testinput", "rect", "10,10,110,50"
mobileControlSet "testinput", "visible", true

This code can be executed in the preOpenCard message to set up the text input control when the user goes to the card.

To get the text that is in the input control use the mobileControlGet function to retrieve the text, the example below puts it into the variable tText

put mobileControlGet("testinput, "text") into tText

I hope that helps.

Kind regards

Elanor

Add your comment

E-Mail me when someone replies to this comment