NIT6120 Mobile Applications
Before you start this lab, make sure you have Android Studio running with emulators or on your devices.
Task 1: Hello World Project
Create a simple “Hello Android World!” Android app that prints to your device’s screen. If you do not have android devices, you may emulator. Make a small change to the app so it displays - Program written by
Hint: Go to Android Window, res folder -> values -> strings.xml
Task 2: DinoQuiz Project (2 marks)
This project is intended to make you aware about the concepts of Android Development. In addition, the app is provided with different layout elements. These are text elements (text widget), graphic elements (image widget) and buttons (button widget).
The finished app has a single screen with one question displaying at a time. When you run an app, the first question will be displayed. You can use “Next” and “Back” buttons to navigate to next and previous questions respectively.
The App Idea
In the DinoQuiz app, it will test users’ knowledge about dinosaurs through questions. A question is asked and different options are provided to select an answer. The game displays a feedback message depending on whether the answer is correct or wrong. There are 5 questions in all.
Are the birds the closest relatives of dinosaurs?
The last surviving dinosaur is the sea monster Nessi.
The Jurassic Park is a sanctuary for dinosaurs.
All dinosaurs were vegetarians.
Rex was the largest dinosaur.
Next task is to add two buttons. You need to define a new Linear layout below the textview to be able to place these buttons next to each other. You can drag and drop the buttons or use xml code.
Your final activity_main.xml file would look like this after adding all components:
xml version="1.0" encoding="utf-8"?>
Layout height is
Density-independent-pixel is a relative variable specification that is always used when the app is supposed to run on different screen sizes with different resolutions. The dp unit is based on a screen resolution of 160 dpi. This means that 1 dp = 1 px (pixel) on a device with 160 dpi.
On a screen with 240 dpi, 1 dp = 1.5 px. The conversion formula is: px = dp * (dpi /160)
Now your design should look like the Figure 1.
Page 8 of 17
Both buttons, namely Correct and Wrong, should respond on clicking and display suitable text on screen depending on whether the answer was correct or wrong. This means that we must establish a contact between button definition in the layout file and the activity (MainActivity.java) which can respond to the user actions and executes one of the actions predefined by us.
The life cycle of the app desired by us presently looks as follows:
Starting the app
MainActivity -> activity_main.xml
A button is clicked -> MainActivity -> Display Message
How can MainActivity respond to the button click?
Resources such as images and text are stored in a R.java file. An activity retrieves information about a resource from the R.java file using the ID. In activity_main.xml file, you can see id for all buttons and textview.
If you want to access a resource from an activity, you must first allocate an ID to it. From the activity, the “Correct button” resource accessed as following:
Edit the MainActivity.java file
Until now, the MainActivity.java contains the code that was automatically generated when creating the project.
An activity is the elementary component of an application that offers an interaction option to the user. You can create or import an interface in an activity using setContentView; the interface normally occupies the entire screen or is embedded in another activity. Various events might occur in the life cycle of an activity and change the activity state e.g. a tap on the Home button or an incoming call can push an activity in the foregrou
Holding a PhD degree in Finance, Dr. John Adams is experienced in assisting students who are in dire need...
55 - Completed Orders
Canada, Toronto I have acquired my degree from Campion College at the University of Regina Occuption/Desi...
52 - Completed Orders
Even since I was a student in Italy I had a passion for languages, in fact I love teaching Italian, and I...
102 - Completed Orders
To work with an organization where I can optimally utilize my knowledge and skills for meeting challenges...
109 - Completed Orders
JOB OBJECTIVE Seeking entry level assignments in Marketing & Business Development with an organization...
202 - Completed Orders
Current work profile Project manager- The Researchers Hub (2nd Jan 2016 to presently working) Researc...
20 - Completed Orders
Sales Assistant, Mito Marina Assigned to the Stationery dept – assisted in merchandising, stock taking...
100 - Completed Orders
Personal Profile Dedicated and highly experienced private chauffeur. High energy, hardworking, punctua...
200 - Completed Orders
I'm Lizzy, full time education specialist in English, Essay Writing, Economics and Maths. Having Assi...
109 - Completed Orders