Common Tasks

Here are some common tasks you might run accross when programming with App Inventor.

 

What can I do with the component block?

The component block can be used for comparison. Here is a sample.

samplecomponent.png

Example Component

 

How can I lock the screen orientation?

You can not lock your screen to a particular orientation, You can however test for the orientation and show different arrangements depending on the screen orientation. Here is a sample code block to illustrate this:

checkorientation.png

How to Check the Orientation

This method has been replaced by the screen orientation feature in the designer.
Now you can select  in Screen1 set ScreenOrientation from Unspecified to Portrait or Landscape

How do I share code with other users?

You can share block images or the .zip file of your code on the forums or here at TheAIRepository.info.
To share the block images, just attach them in an e-mail to the forum you want to post in. If it is on the Programming or coffee shop forums, I will usually ask if it is ok to re-post
To create the image, just do a screen capture by hitting alt print screen and then crop if needed with your favorite paint program.
To create the .zip files of your source, goto the MyProjects section of the App Inventor designer, check the box next to the code you want, click More Actions and then click Download Source to send the source to someone else.
If you receive a .zip you can goto the MyProjects section in the designer, click More Actions and then click Upload Source.

 

How do I restart a timer?

Disable the timer and then re-enable it will reset the timer.

 

How can I add an icon to my app?

You can add an icon to the app by specifying an file for the icon on the screen component in the design view.
Note: The icon should be approximately 48×48. There is currently a bug in AppInventor that is not allowing you to use a standerd .ico file as the icon. You will get a Server Build Error Occured error.

 

How can I figure out the Action, Activity Package and Activity Class to use with an Activity Starter?

if you want to find out the
settings for using one of the phone’s apps, with your phone connected,
1. Goto a command prompt on your PC.
2. Switch to the appinventor extras directory by typing cd “C:\Program Files
(x86)\AppInventor\commands-for-Appinventor”
3. Start adb logcat and wait a few seconds for all the commands to finish.
4. goto your phone and launch the application you wish to get the
Information from.
5. Wait a few seconds for the app to launch then go back to your command
prompt window and look for the act section.
6. The cmd section contains the ActivityPackage and ActivityClass
information.

Below taken from
http://experimental.appinventor.mit.edu/learn/reference/other/activitystarter.html
Figuring out how to set the properties

If you can’t find documentation for the activities you want to start, one
way to figure out how to set the properties is to start up the activity
manually and look at what appears in the Android System Log. For example, if
you use YouTube to play a video, you’ll see in the log:

I/ActivityManager( 86): Starting activity: Intent {
act=android.intent.action.VIEW cat=[android.intent.category.BROWSABLE] dat=
http://www.youtube.com/watch?v=8ADwPLSFeY8 flg=0×3800000
cmp=com.google.android.youtube/.PlayerActivity }

If you can find the “cmp=” string, then the ActivityPackage is the part
before the slash, and the ActivityClass is is the entire “cmp=” part without the slash. As in
the YouTube example, there may also be “dat=” information that can specify
with the DataUri property.

 

How do I Pause a Program with App Inventor?

Here is a simple pause routine to illustrate how to pause an game or activity.

pauseroutine.png

How to Pause a timer.

We start off by changing the text on the button so the user knows what to do.
Under the Pause and Resume activity you start or stop any animation or timers that you need to pause or start the activity.
Then you save the current state of the game to the tiny DB. This part could be under the pause and resume activity routines but I show it here just to remind you that you need to save the state in case the application gets terminated by the garbage collector.

 

How can I create an about screen?

Add a notifier to display the screen and an about button to your project. Call the notifier on the about button.click. Define whatever you want to display on the button. See either the blockout.zip or nearheregps(2).zip under source code  for an example.

 

How do I cut and paste blocks?

Hit ctrl-c to cut then ctrl-v to paste.

 

How can I cut and past multiple blocks?

You can nest all the blocks you want to copy in an if block, then when you copy the if block it will copy all the nested blocks. Then move the copied blocks where you need them and delete the if block.

 

How can I make a button doubleclick?

Add a timer to your project, set the timer interval to 1000ms
Add a variable to your project called ClickCount set it = 1.
On timer, reset ClickCount = 1
In button click, ad an ifelse block. The first time the button is clicked, set ClickCount to +=1, the second time it is clicked do what is in the else part of the if else.
Click count will reset after 1000 ms.

doubleclick.png

How to DoubleClick

 

How do I set up my own TinyWebDB?

This thread in the Programming App Inventor group has some good info Looking for advice with tinywebdb – Google Groups

 

 How do I connect the Bluetooth to my Lego@ Mindstorm@ robot?

You need Android 2.0 or greater to connect to the NXT, here are some instructions:

  1. On the robot, click the right arrow until it says Bluetooth, then press the orange square.
  2. Click the right arrow until it says Visibility, then press the orange square.
  3. If it says Visible, that’s good. If not, click the left or right arrow until it says Visible.
  4. On the Android, Bluetooth pairing is done in Settings -> Wireless & Networks. (That’s where it is on my Nexus One.)
  5. Make sure the Bluetooth checkbox is checked.
  6. Then, click Bluetooth settings and Scan for devices.
  7. Under “Bluetooth devices”, look for a device named “NXT” (or whatever your robot’s name is, if you’ve ever changed it).
  8. If it says “Paired but not connected” under your robot’s name, that’s good. You’re done!
  9. If it says “Pair with this device” under your robot’s name, click on it.
  10. On the robot, it should be asking for a pass key and suggesting 1234. Press the orange square.
  11. On the Android, it should be asking for the PIN. Enter 1234 and press OK.
  12. It should now say “Paired but not connected”.
If you are using the emulator, you have to make a LOT of changes.
Search for “bluetooth android emulator” and be prepared to be sad.
and if you get it working, let us know,

 

How can I Simulate an Multi Tabbed App?

See the source code for MultiTabSimulated under Source Code.

 

How can I simulate a MultiScreen App?

To simulate a multiple screen app, you need to create your app with multiple arrangements that you can turn off and on depending upon the location in the app. I.E. Put a horizontal arrangement in your app and rename it to screen1Arrangement. Put all the stuff into the scfreen1Arrangement that you want to show up when the user is at screen one. When the user presses a button to goto the next screen, hide the screen1Arrangement and show the next arrangement.

 

How can I create a simulated Horizontal Rule element to help layout my app?

To simulate an horizontal Rule element, Create a canvas set width to fill parent, set height to 1 pixel
Set the paint color to whatever color you want to make the line.
Set the x and y properties of the draw line function like the image below.

horizontalrule.png

How to Create a Horizontal Rule

 

Layout Behavior laid out

How to from by Stephen Zipprich

Open a Google Map

Use an activity starter with the following settings:
Action = android.intent.action.VIEW
Activity = com.google.android.maps.MapsActivity
Package = com.google.android.apps.maps
DataURI = Geocode or location i.e. geo:0,0?q=Metreon, San Francisco, CA

 

Open Google Navigation

Use an activity starter with the following settings:
Action = android.intent.action.MAIN
Activity = com.google.android.maps.driveabout.app.NavigationActivity
Package = com.google.android.apps.maps
DataURI = URL or geocode of destination.

 

Open Google MyMaps

Use an activity starter with the following settings:
Action = android.intent.action.MAIN
Activity = com.google.android.maps.MapsActivity
Package = com.google.android.apps.maps
DataURI = URL of saved map.

 

Choosing colors in App Inventor

App Inventor uses an encoded number for setting the color. It is derived by setting the different values for R G B and then computing an integer value. You can find the reference documentation here. There are also a couple neat little utilities to help you find the color.
One is James Laroche’s CSS color chart located Here.

 

What does the image1.animation block do?

It scrolls an image to the left or right.
Possible values are:
“ScrollLeft”, “ScrollLeftSlow”, “ScrollLeftFast”
“ScrollRight”, “ScrollRightSlow”, “ScrollRightFast”

 

Why doesn’t my tinyDB save data between restarts of my application?

Did you install the application to your phone or are you just running it through the blocks editor?
TinyDB persistence does not work on the emulator or direct connect. You must actually install the application to the phone for persistence to work.

 

How do I make a null text?

Make a text – > text block and then delete the text out of it.

 

How do I use the advanced options in the blocks editor?

The advanced options can be used for cycling through component lists. See the advanced templates on the code site to see how I use the advanced components to loop through screens and buttons and lists.

My Application doesn’t close, what can I do?

This problem usually happens when you have more than one screen open. Make sure you are closing screens to return to your main screen instead of just opening another screen and leaving the screen you left in the background. Generally, when you try to use the close application block it will go to one of the open pages instead of closing the application.

Leave a Reply