Skip to main content

Featured

Space Explorers Book 7: Answers and Explanations

Memunic Space Explorers › Book 7: Memoon and the Search for Another Home › Answers and Explanations Answers and Explanations Habitable means life could live there; inhabited means life does live there. A world can be habitable and empty, as an unoccupied flat has a roof and water but nobody in it. The Moon has almost no air, so water would boil or freeze, and its gravity is only about one-sixth of Earth’s, too weak to keep air. Accept also: no greenhouse blanket, so it swings between very hot and very cold. Venus. It matches Earth in size and roughly in mass, but its thick carbon dioxide air traps heat, making it hot and crushing. “Twin” is only true for size and weight. A dip of 1 per cent means (planet width divided by star width) squared is 0.01, so the ratio is 0.1: the planet is about a tenth as wide as the star. Repeats at the same gap show the planet is going round the star in 12 days, and rule out a one-time event such as a passing object. A planet shines only by reflected l...

Byte by Byte Book 7: Chapter 11 – Building Mobile Apps with MIT App Inventor

Byte by Byte › Book 7: Networks, Programming and Machine Learning › Chapter 11: Building Mobile Apps with MIT App Inventor

Chapter 11: Building Mobile Apps with MIT App Inventor

You will learn: what an app is and the main types of mobile app, the stages of app development, how to plan an app with a wireframe, the Designer and Blocks editors in MIT App Inventor, visible and non-visible components, event-driven programming, variables, lists, procedures and decisions in blocks, saving data with TinyDB, testing on a phone with the AI Companion, and app permissions, privacy and publishing.

🔎 The Case

The question of the videos would have to wait one more day, because the clips were spreading faster than anyone could explain them.

By morning they had been forwarded more than twenty thousand times. Not on websites, which people visited when they chose to, but phone to phone, family group to family group. Hop's grandmother had received the same clip from four different relatives before breakfast, each with a message: Is this true?? Forward to everyone!

"People don't come to the Truth Desk," said Quill gloomily. "The lies come to them. Into their pockets. By the time they think of checking our site, they have already pressed Forward."

Luna, who had stayed at Snowpeak to help, was looking at her phone. "Then the Truth Desk has to be in their pockets too," she said. "A little app. Something you open in the two seconds before you forward. Type what the message is about, and it tells you if we've already checked it."

Memoon had built games, websites and Python programs, but never an app for a phone. "Do I need to learn a whole new language?"

"Not to start with," said Nimo. "Remember Scratch? There's a tool that builds real phone apps out of blocks. You'll recognise it in about four seconds."

💡 The Concepts

What is an app? An app (application) is software designed to do particular tasks for its user (Book 6). Mobile apps run on phones and tablets, which bring special abilities that desktop computers usually lack: touchscreens, cameras, microphones, GPS location, motion sensors, notifications, and being with you all the time. In India, many people's first and only computer is a smartphone, so mobile apps are how they bank, learn, shop, travel and get the news.

Types of mobile app.

TypeHow it is madeStrengthsExample
Native appBuilt for one operating system (Android or iOS) using its own tools and languages, such as Kotlin or SwiftFastest; full use of the phone's hardwareCamera apps, most games
Web appA responsive website (Chapter 10) that behaves like an app, used in the browserWorks on any device; no installationMany news and shopping sites
Hybrid / cross-platform appWritten once, then packaged to run on both Android and iOSOne code base for bothMany business and banking apps

Apps are downloaded from an app store: the Google Play Store for Android and the Apple App Store for iPhone.

The app development life cycle. Professional apps are built in stages. It is the same problem-solving cycle you have used throughout this series, with one difference: it repeats, because real apps are improved and updated for years.

  1. Idea and research: what problem does it solve, and for whom? Do similar apps already exist?
  2. Plan and design: decide the features; sketch every screen as a wireframe, a simple box drawing showing where each element goes; plan how the user moves between screens.
  3. Build: create the user interface and write the code.
  4. Test: try it on real devices, with real users, including normal, boundary and invalid inputs.
  5. Release: publish it, or share it with its users.
  6. Maintain: fix bugs, respond to feedback, add features, release updates.

MIT App Inventor. MIT App Inventor is a free, browser-based tool from the Massachusetts Institute of Technology for building real Android (and iPhone) apps with blocks. It is used in schools all over the world, including in Indian Class 8 computer courses. You reach it at ai2.appinventor.mit.edu and sign in with a Google account (a grown-up should help). Your projects are saved automatically in the cloud, so it is a SaaS and PaaS tool in one (Chapter 2).

App Inventor has two main views, switched with buttons at the top right.

  1. The Designer is where you build what the app looks like.
PanelWhat it holds
Palette (left)All the components you can add, in groups: User Interface, Layout, Media, Sensors, Storage and more
Viewer (centre)A preview of the phone screen; drag components onto it
Components (right of centre)A tree of everything on the screen, where you can rename components
Properties (right)Settings for the selected component: text, colour, size, font, image and so on

A component is any building block of an app. Visible components appear on the screen: Button , Label , TextBox , Image , ListView , Slider , CheckBox . Non-visible components work behind the scenes and appear below the Viewer: Clock (timers), TinyDB (storage), TextToSpeech , Notifier (pop-up messages), Sound , AccelerometerSensor , LocationSensor .

Layout components such as HorizontalArrangement and VerticalArrangement hold other components in a row or a column, the App Inventor version of Flexbox (Chapter 10).

Good habit: rename every component as soon as you add it. ButtonCheck and LabelResult are much easier to find in the Blocks editor than Button3 and Label7 . Programmers call these meaningful names.

  1. The Blocks editor is where you make the app do things. It looks very like Scratch: you

drag blocks from drawers on the left and snap them together. Each component you added in the Designer has its own drawer of blocks in three colours:

  • Event handlers (gold): when ButtonCheck.Click do . These start code running when something happens.
  • Property getters and setters (green): set LabelResult.Text to , TextBoxClaim.Text .
  • Methods (purple): actions a component can perform, such as call TextToSpeech1.Speak or call TinyDB1.StoreValue .

The built-in drawers hold general blocks: Control (if, loops), Logic, Math, Text, Lists, Variables and Procedures.

Event-driven programming. Python programs usually run from top to bottom. Apps are different: they sit waiting until something happens, such as a tap, a timer tick, or a message arriving, and then respond. This is event-driven programming, exactly like the hat blocks in Scratch (Book 4). Every piece of code in an App Inventor app lives inside an event handler. The first event in every app is when Screen1.Initialize , which runs once when the app opens.

Programming ideas in blocks. Everything you learned in Python exists in App Inventor, as blocks. In this book, App Inventor scripts are written as text, using the same notation as the Scratch scripts in Book 5: block names in normal text, drop-down choices in [square brackets], values typed or plugged in shown in (round brackets), and blocks inside other blocks indented.

PythonApp Inventor block

score = 0 (a global initialize global [score] to (0) variable)

score = score + 1set global [score] to ((get global score) + (1))

if ... elif ... else if / else if / else (click the blue gear to add branches)

"Hello " + namejoin ("Hello ") (TextBoxName.Text)
claims = ["a", "b"]make a list ("a") ("b")

claims.index(x) + 1 index in list thing (x) list (claims) , which gives 0 if not

found

claims[i - 1]select list item list (claims) index (i)
def check():to procedure [check] do
for item in claims:for each [item] in list (claims)

One important difference: App Inventor lists count from 1, not from 0 like Python. The first item is at index 1. Watch for this whenever you move between the two.

Procedures. A procedure is App Inventor's name for a function (Chapter 6). Use to procedure do for one that just does something, and to procedure result for one that returns a value. Give them parameters with the blue gear. As in Python, they stop you repeating code.

Storing data with TinyDB. When an app closes, its variables are lost, like RAM (Book 6). TinyDB is a non-visible component that stores data permanently on the phone, under a name called a tag, like a key in a Python dictionary (Chapter 7).

  • call TinyDB1.StoreValue tag ("checks") valueToStore (get global checks) saves a value.
  • call TinyDB1.GetValue tag ("checks") valueIfTagNotThere (0) reads it back, with a default for the first time the app runs, just like .get() with a default.

TinyDB data stays on that one phone. Sharing data between users needs a cloud database such as CloudDB or Firebase, which App Inventor also offers.

Testing on a real phone. App Inventor can run your app live on a phone while you build it.

  1. A grown-up installs the free MIT AI2 Companion app on an Android phone or tablet (it is also available for iPhone) from its app store.
  2. The phone and the computer must be on the same Wi-Fi network.
  3. In App Inventor, click Connect → AI Companion. A six-letter code and a QR code appear.
  4. In the Companion app on the phone, scan the QR code or type the code.
  5. Your app appears on the phone. Every change you make in the Designer or Blocks editor appears on the phone within a second or two. This is called live testing.

If you do not have a phone available, Connect → Emulator shows a phone on your computer screen instead (it needs extra software that a grown-up can install from the App Inventor website).

When the app is finished, Build → Android App (.apk) creates an installable file. An APK (Android Package) is the file format for Android apps.

Permissions and privacy. Apps must ask permission before using the camera, microphone, location, contacts or files. Before you tap Allow on any app, ask the questions from Chapter 3 and the CBSE privacy checklist: Why does it need this? Who can see it? How long is it kept? A torch app that wants your contacts is a warning sign. When you build apps, request only the permissions your app really needs.

Publishing. Publishing to the Google Play Store needs a developer account with a fee, and Google requires developers to be adults, so student apps are usually shared as APK files with family, friends or a school, always with a grown-up's permission. Installing an APK from outside the Play Store needs the phone's setting for unknown sources to be allowed, which is also how malware gets onto phones (Book 6), so only ever install APKs from people you know and trust.

Real World: India's government has built many widely used apps: UMANG (hundreds of government services in one app), DigiLocker, mAadhaar, BHIM for UPI payments, and Sachet, which sends official disaster and weather alerts. The Bhashini project (Book 6) helps apps work in many Indian languages.

Career Spotlight: Mobile app developer. Mobile developers build the apps on our phones, from games to banking. They think about small screens, slow networks, battery life and privacy, and test on many different phones. Many started by building a tiny app for a problem they had themselves.

Illustration from Byte by Byte Book 7: Chapter 11 – Building Mobile Apps with MIT App Inventor

🛠️ Build It

You will build Stop Check Share: type a word from a message you have received, tap Check, and the app tells you whether the Truth Desk has already checked a claim about it. It also counts how many checks you have done, even after the app is closed.

Step 1: Plan. On paper, draw a wireframe of one phone screen with: a title, a text box with a hint, a Check button, a large result label, a "Read it aloud" button, and a small label at the bottom showing "Checks done: 0". Mark which parts the user touches.

Step 2: Start the project.

  1. Go to ai2.appinventor.mit.edu and sign in (with a grown-up).
  2. Click Projects → Start new project, and name it StopCheckShare (no spaces allowed).
  3. Select Screen1 in the Components panel. In Properties, set Title to Stop Check Share , AppName to Stop Check Share and BackgroundColor to a colour you like.

Step 3: Design the screen. Drag these components onto the Viewer in order, renaming each one (select it and click Rename below the Components tree) and setting its properties:

Component (Palette

Rename toProperties to set

group)

Label (User Interface) LabelTitle Text: Before you forward, check it. ;

FontSize: 20; FontBold: ticked

TextBox (User TextBoxCla Hint: Type one word from the message ;

Interface)imWidth: Fill parent

Button (User ButtonChec Text: Check ; FontSize: 18; Width: Fill parent

Interface)k
Label (User Interface)LabelResul tText: (empty); FontSize: 22; FontBold: ticked
Button (User Interface)ButtonSpea kText: Read it aloud

Label (User Interface) LabelCount Text: Checks done: 0 ; FontSize: 12

TextToSpeech (Media)Speaker(non-visible)
TinyDB (Storage)Storage(non-visible)

Step 4: Connect a phone. Click Connect → AI Companion and scan the code with the Companion app. Your screen should appear on the phone. Keep it connected while you build.

Step 5: Program it. Click Blocks. Build these scripts. (Look in the drawers: Variables for initialize global , Lists for make a list , Control for if , Text for join and "" , and each component's own drawer for its blocks.)

First, three global variables: the claims the Truth Desk has checked, their verdicts in the same order, and the count.

initialize global [claims] to (make a list ("guardian") ("exam") ("echo") 
("water"))
initialize global [verdicts] to (make a list ("FALSE: the photo is fake") 
("TRUE: results on Monday") ("FALSE: it is a scam") ("FALSE: the water is 
safe"))
initialize global [checks] to (0)

When the app opens, load the saved count:

when [Screen1].Initialize
  set global [checks] to (call [Storage].GetValue tag ("checks") 
valueIfTagNotThere (0))
  set [LabelCount].Text to (join ("Checks done: ") (get global checks))

A procedure that looks up the claim and shows the result:

to procedure [checkClaim]
  initialize local [position] to (index in list thing (downcase (trim 
(TextBoxClaim.Text))) list (get global claims))
    in
      if ((get position) > (0))
        then
          set [LabelResult].Text to (select list item list (get global 
verdicts) index (get position))
        else
          set [LabelResult].Text to ("Not checked yet. Don't forward it. 
Report it to the Truth Desk.")

( trim and downcase are in the Text drawer. They work like .strip() and .lower() in Python, so Guardian still matches guardian . initialize local ... in is in the Variables drawer.)

When Check is tapped, run the procedure, add one to the count, save it and show it:

when [ButtonCheck].Click
  call [checkClaim]
  set global [checks] to ((get global checks) + (1))
  call [Storage].StoreValue tag ("checks") valueToStore (get global 
checks)
  set [LabelCount].Text to (join ("Checks done: ") (get global checks))

When Read it aloud is tapped, speak the result:

when [ButtonSpeak].Click
  call [Speaker].Speak message (LabelResult.Text)

Step 6: Test. On the phone, try: guardian , GUARDIAN , exam (with spaces), rainbow (not in the list), and an empty box. Write down what happens each time. Close the app completely and reopen it: is the count still there? That is TinyDB at work.

Step 7: Improve it. Choose two:

  • If the text box is empty, show "Please type a word first" and do not add to the count. (Hint: is empty in the Text drawer.)
  • Colour the result: set LabelResult.TextColor to red when the verdict starts with FALSE and green when it starts with TRUE. (Hint: the Text drawer's contains block, or compare the first five characters using segment .)
  • Add a third list of source links, and a button that opens the source. (Hint: an ActivityStarter component, or just show the link in a label.)
  • Add a Clock component and a "Pause 10 seconds before sharing" button that counts down from 10 in a label, one second at a time, using when Clock1.Timer .

Step 8: Build and share. With a grown-up, click Build → Android App (.apk) and install it on a family phone. Ask two people to use it without any help from you, and watch where they get confused. Write down one change you would make.

Unplugged: Event cards. One person is the app; they hold a set of cards, each with an event on the front ( when ButtonCheck.Click , when Screen1.Initialize , when Clock1.Timer ) and the actions on the back. The rest of the group are "users" and the "phone": they cause events in any order ("I tap Check!", "One second passes!", "The app opens!"). The app must find the right card and act out the back. Notice that the app never knows what will happen next. That is event-driven programming.

✅ Case Closed

By the evening, Stop Check Share was on four hundred phones across Memunic. Luna had shared it with every family in Moonbrook. Hop had shown it to his grandmother, who used it eleven times before dinner and then started showing it to her friends.

The number that mattered most was one that Frost could see at the hub: the clips were still being forwarded, but far more slowly. People were pausing. Two seconds of checking was enough to break the chain.

But the app could only check claims the Truth Desk had already investigated. For the videos, the honest verdict was still "Not checked yet". Nobody had proved they were fake.

That night Memoon played one of the clips over and over, frame by frame. Simbha's mouth opened. His mane rippled as he turned. His eyes blinked. On the twelfth viewing she noticed something: just as the clip began, for a fraction of a second, the edge of his mane seemed to flicker and slide, as if it was not quite attached to his head.

"Nimo," she said, "how many pictures make one second of video?"

❓ Test Yourself

  1. Name three abilities phones have that most desktop computers do not, and one app that uses each.
  2. What is the difference between a native app, a web app and a hybrid app?
  3. List the six stages of the app development life cycle. Why does it repeat?
  4. What is a wireframe, and why do designers make one before building?
  5. What is the difference between the Designer and the Blocks editor in App Inventor?
  6. Sort into visible and non-visible components: Button, Clock, TinyDB, Label, TextToSpeech, Image, TextBox, Notifier.
  7. What is event-driven programming? Name two events that could start code in an app.
  8. In App Inventor, what index does the first item in a list have? How is that different from Python?
  9. What does TinyDB do? Why is it needed if the app already has variables?
  10. How do you test an App Inventor app on a real phone while you build it?
  1. Before allowing an app to use your location, what three questions should you ask?
  2. Challenge: Design (on paper) an app that helps your class remember homework. Draw a wireframe, list every component with a meaningful name, and write the event-handler scripts in block notation. Which data must be saved with TinyDB?

📚 Key Terms

  • Mobile app: an application designed for phones and tablets.
  • Native app: an app built for one operating system with its own tools.
  • Web app: a website that behaves like an app in a browser.
  • Hybrid (cross-platform) app: an app written once to run on several operating systems.
  • App store: an online shop for downloading apps, such as Google Play.
  • App development life cycle: the stages of planning, building, testing, releasing and maintaining an app.
  • Wireframe: a simple sketch of a screen's layout.
  • MIT App Inventor: a free block-based tool for building mobile apps.
  • Designer / Blocks editor: App Inventor's view for building the screen / for programming behaviour.
  • Component: a building block of an App Inventor app.
  • Visible / non-visible component: one that appears on the screen / one that works behind the scenes.
  • Property: a setting of a component, such as its text or colour.
  • Event handler: code that runs when a particular event happens.
  • Event-driven programming: programming in which code runs in response to events.
  • Procedure: App Inventor's name for a function.
  • TinyDB: an App Inventor component that stores data permanently on the device.
  • Tag: the name under which TinyDB stores a value.
  • AI Companion: the app that runs App Inventor projects live on a phone.
  • Live testing: seeing changes to an app immediately on a real device.
  • APK: the installable file format for Android apps.
  • App permission: an app's request to use a phone feature such as the camera or location.

Keep learning with Byte by Byte

Explore Book 7: Networks, Programming and Machine Learning. Find the ebook, purchase details and teaching slides on MemuniCity.

Watch this chapter on YouTube

Comments

Popular posts from this blog

CA-7 Job Status and Failure Reason Codes

Here are the various status codes that You may see for jobs in the Queue or Logs in CA-7. R-C0002 R-C0003 R-C0099 R-C0255 R-JCLER A-U0002 A-U0004 A-U0015 A-U0043 A-U4095 A-SOC7 A-U4000 Reason Code/Job Status Code explanation: The indication of the job's current disposition. Values and their meanings are: A-Snnnn-- The job has failed with a system abend. A-Unnnn --The job has failed with a user abend. C-Cnnnn --The job has completed successfully and is going through completion processing. E-ARFATT-- An error occurred during the attempt to attach ARF definitions. This can result if the ARFSET specified is not defined. A diagnostic message may have been written to the CA-7 log, the OS console, or to the trailer queue for the job (in which case it can be displayed using LQ,JOB=x,LIST=ALL). E-ARFERR ---The job encountered an error in the ARF processing. Do a LARFQ command for the job to get more specific information. E-SEGERR --The job has been requeued...

Whistling Winds and Waterfalls: 4 Days of Magic in Shillong

Nestled in the clouds, where the scent of pine trees mingles with the rhythm of waterfalls and the tunes of local guitar-strumming youth—Shillong is more than a place. It’s a vibe. If you’ve got 3 nights and 4 days, you’ve got just enough time to fall in love. Here’s how to make the most of it—food, fun, fog and fantastic views included. Day 1: Shillong, We’re Coming for You! You land in Guwahati, barely out of the airport when the hills start calling. You hop into your cab, Spotify on, windows down, and the three-hour ride to Shillong begins. Just when you think it can’t get better, you stop at Umiam Lake —a lake so calm, it looks like someone ironed the water. By evening, you’re sipping hot chai in Laitumkhrah, maybe nibbling on spicy momos or pork jadoh from a roadside stall. You’re checked into your charming hotel ( Tripura Castle if you fancy old-world royalty, Ri Kynjai if you’re into lakeside poetry). The breeze whispers secrets of waterfalls and pine forests. Sleep well, drea...

Installing and Configuring Hadoop on Ubuntu as a Pseudo Distributed Single Node Cluster

Briefly what is psuedo-distributed single node Hadoop cluster: It is a Hadoop distributed cluster having Single Node. All the five daemons (NN,DN,JT,TT,SNN) are running as individual JVM (java process) instances. We will get all distributed features of Hadoop. This mode is used to develop, test, and staging (before production) Map Reduce programs quickly. It writes all the system, daemon and user logs to different files on the cluster To install Hadoop in this mode, we have to modify the hadoop-env.sh, core-site.xml, hdfs-site.xml, mapred-site.xml. hadoop-env.sh contains all the Environment variables which are required for running Hadoop. All the default values are fine, Only we have to modify the JAVA_HOME=“The location of Java Home Directory” Core-site.xml contains all the cluster specific information like io, temp directory, sorting, file system uri etc. Hdfs-site.xml contains all the parameters which are specific to HDFS like name node directory, data node directory...