O'Reilly logo

Learning MIT App Inventor: A Hands-On Guide to Building Your Own Android Apps by Mark Sherman, Derek Walter

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Global Variables

Global variables need to be initialized before they can be used. The initialize global block does three things: creates the variable, gives it a name, and sets its initial value.

Choose the initialize block from the Variables built-in menu, and then click in the Name field to replace the word name with a useful name. The initialize block must have an initial value. This is similar to setting a value of a component property in the Designer; you have to put in something for the app to have in that variable when it starts. A variable cannot be truly empty.

Usually, the value given to the initialize block is useful and relevant, such as setting a counter variable to start at zero. Sometimes you just need space for later and you ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required