MAP524/DPS924 MOBILE APP DEVELOPMENT (ANDROID) MIDTERM TEST OCTOBER 2013 STUDENT NAME STUDENT NUMBER



Similar documents
ANDROID AS A PLATFORM FOR DATABASE APPLICATION DEVELOPMENT

Android Introduction. Hello Mihail L. Sichitiu 1

Developing an Android App. CSC207 Fall 2014

Now that we have the Android SDK, Eclipse and Phones all ready to go we can jump into actual Android development.

Tutorial #1. Android Application Development Advanced Hello World App

2. Installieren des MySQL Workbench (Version ) 3. Unter Database > Manage Connection folgende Werte eintragen

Arduino & Android. A How to on interfacing these two devices. Bryant Tram

Report and Opinion 2014;6(7) Technical Specification for Creating Apps in Android. Kauser Hameed, Manal Elobaid

Android For Java Developers. Marko Gargenta Marakana

Developing Android Apps: Part 1

By sending messages into a queue, we can time these messages to exit the cue and call specific functions.

Android Quiz App Tutorial

Getting Started: Creating a Simple App

Android Development Tutorial

Chapter 2 Getting Started

Saindo da zona de conforto resolvi aprender Android! by Daniel Baccin

MMI 2: Mobile Human- Computer Interaction Android

ANDROID APP DEVELOPMENT: AN INTRODUCTION CSCI /19/14 HANNAH MILLER

ECWM511 MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction to Android

Android 多 核 心 嵌 入 式 多 媒 體 系 統 設 計 與 實 作

Android Application Development: Hands- On. Dr. Jogesh K. Muppala

directory to "d:\myproject\android". Hereafter, I shall denote the android installed directory as

4. The Android System

Android Development. Marc Mc Loughlin

Getting Started With Android

Tutorial: Setup for Android Development

Android Application Development. Yevheniy Dzezhyts

ANDROID APPS DEVELOPMENT FOR MOBILE AND TABLET DEVICE (LEVEL I)

Android Java Live and In Action

Android Development. 吳 俊 興 國 立 高 雄 大 學 資 訊 工 程 學 系

Mobile Application Development

Università Degli Studi di Parma. Distributed Systems Group. Android Development. Lecture 2 Android Platform. Marco Picone

Android Programming. Android App. Høgskolen i Telemark Telemark University College. Cuong Nguyen,

Presenting Android Development in the CS Curriculum

How to develop your own app

Android Programming Basics

Based on Android 4.0. by Lars Vogel. Version 9.8. Copyright 2009, 2010, 2011, 2012 Lars Vogel Home Tutorials Trainings Books Social

Introduction to Android SDK Jordi Linares

Building Your First App

Create Android apps that stand out from the crowd. Android. Best Practices. Godfrey Nolan Onur Cinar David Truxall

getsharedpreferences() - Use this if you need multiple preferences files identified by name, which you specify with the first parameter.

How to build your first Android Application in Windows

Android Basics. Xin Yang

Android Persistency: Files

Developing Android Applications: Case Study of Course Design

Android App Development Lloyd Hasson 2015 CONTENTS. Web-Based Method: Codenvy. Sponsored by. Android App. Development

Performance - Optimierung. mit und ohne Android Developer Tools. Dominik Helleberg

App Development for Smart Devices. Lec #4: Services and Broadcast Receivers Try It Out

ELET4133: Embedded Systems. Topic 15 Sensors

Tutorial for developing the Snake Game in Android: What is Android?

Android Bootcamp. Elaborado (com adaptações) a partir dos tutoriais:

2. Click the download button for your operating system (Windows, Mac, or Linux).

Android Concepts and Programming TUTORIAL 1

ACKNOWLEDGEMENT VISHNU RAMAKRISHNAN VISHNU SANKER ANAGHA OK PRANAM SREEDHARAN

App Development for Android. Prabhaker Matet

Android Services. Services

Admin. Mobile Software Development Framework: Android Activity, View/ViewGroup, External Resources. Recap: TinyOS. Recap: J2ME Framework

Advantages. manage port forwarding, set breakpoints, and view thread and process information directly

Android Environment SDK

Android Persistency: SQL Databases

Android App Development. Rameel Sethi

ANDROID TUTORIAL. Simply Easy Learning by tutorialspoint.com. tutorialspoint.com

CSE476 Mobile Application Development. Yard. Doç. Dr. Tacha Serif Department of Computer Engineering Yeditepe University

Android Security Lab WS 2014/15 Lab 1: Android Application Programming

HERE SDK for Android. Developer's Guide. Hybrid Plus Version 2.1

Android Programming Tutorials. by Mark L. Murphy

TUTORIAL. BUILDING A SIMPLE MAPPING APPLICATION

Android Development Tutorial. Human-Computer Interaction II (COMP 4020) Winter 2013

An Introduction to Android Application Development. Serdar Akın, Haluk Tüfekçi

Developing NFC Applications on the Android Platform. The Definitive Resource

Introduction to Android. CSG250 Wireless Networks Fall, 2008

Orders.java. ArrayList of Drinks as they are ordered. Functions to calculate statistics on Drinks

Android Development Exercises Version Hands On Exercises for. Android Development. v

Login with Amazon Getting Started Guide for Android. Version 2.0

Specialized Android APP Development Program with Java (SAADPJ) Duration 2 months

Android Apps Development Boot Camp. Ming Chow Lecturer, Tufts University DAC 2011 Monday, June 6, 2011

23442 ECE Introduction to Android Mobile Programming ECE Special Topics: Android Mobile Programming

Developing apps for Android OS: Develop an app for interfacing Arduino with Android OS for home automation

Hello World. by Elliot Khazon

Q1. What method you should override to use Android menu system?

A software stack for mobile devices:

Basics of Android Development 1

Les fragments. Programmation Mobile Android Master CCI. Une application avec deux fragments. Premier layout : le formulaire

Android Programming. An Introduction. The Android Community and David Read. For the CDJDN April 21, 2011

Transcription:

MAP524/DPS924 MOBILE APP DEVELOPMENT (ANDROID) MIDTERM TEST OCTOBER 2013 STUDENT NAME STUDENT NUMBER Please answer all questions on the question sheet This is an open book/notes test. You are allowed to use 1 text book plus your own notes. No electronic aids are allowed. This is a 90 minute test and is worth 30% of your final grade. There are 22 questions worth 40 marks in total.

Multiple Choice. NOTE: Each question has only one BEST answer. Each question is worth one mark. 01. The plus (+) sign in the statement android:id="@+id/my_id" will a) identify it as an id resource. b) create a new id and add it to the project resources. c) call the xml parser to expand the id string. d) both a) and b). 02. Which of the following Java code samples could be used to apply an XML layout resource to an Activity? a) findviewbyid(r.id.help); b) setcontentview(r.layout.help); c) addcontentview(r.layout.help); d) setvisible(true); 03. Which of the following is not one of the pre-defined Android View Groups? a) RelativeLayout b) FixedLayout c) GridLayout d) TableLayout 04. Which of these methods is called first when an Activity is initially launched? a) onstart() b) onpause() c) oncreate() d) onresume() 05. In which of the following locations would you include XML code to define a menu resource, including the menu items? a) res/xml/main_menu.xml b) res/menu/main_menu.xml c) res/menus/main_menu.xml d) res/layout/main_menu.xml 06. Which of the following defines a row within the XML for a TableLayout? a) <TableRow> b) <Row> c) <TableRowView> d) <RowView> 07. Which of the following classes is used to display a message only for a moment? a) Alert b) Context c) Toast d) Message 08. Which of the following is the correct signature for the "onclick" method in an OnClickListener? a) public void onclick(activity a) b) public void onclick(view v) c) public void onclick(context c) d) public View onclick(this) 09. Which of the following is used to bind data to a layout View? a) Activity b) Context c) Intent d) Adapter 10. When does a context menu appear? a) on pressing b) on long-pressing c) on pressing the menu button d) on swiping

Write one line Android CLI command for each of the following. Each question is worth 1 mark. 11. List all current Android devices. adb devices or android list avd 12. Copy a local file named android.mp4 to the /sdcard/movies directory. adb push ~/android.mp4 /sdcard/movies/android.mp4 13. Copy a database file named students.db from your phone to a local file. The package name is ca.on.senecac.myapp. adb pull /data/data/ca.on.senecac.myapp/databases/students.db ~/students.db 14. Start a shell on the current Android device. adb shell 15. Install an Android application package named MyApp.apk onto the current Android device. adb install MyApp.apk 16. View the current logcat file. adb logcat 17. Create a new Android project with package name com.example.helloandroid and activity name of HelloAndroid. android create project name HelloAndroid package com.example.helloandroid 18. Launch an emulator with name of my_phone. emulator -avd my_phone 19. List all packages installed on the current Android device. adb shell pm list packages 20. Compile your project in debug mode. ant debug

21. Draw the layout represented by the following XML file. Identify the colours used for the texts and backgrounds as well as the position of all views on the screen. [ 10 marks ] <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > android:id="@+id/textview01" android:background="#00f" android:text="red" android:textcolor="#fff" /> android:id="@+id/textview02" android:layout_alignparentright="true" android:background="#ffff00" android:text="green" android:textcolor="#000" /> android:id="@+id/textview03" android:layout_centervertical="true" android:layout_toleftof="@+id/textview02" android:background="#0f0" android:text="yellow" android:textcolor="#000" /> android:id="@+id/textview04" android:layout_centervertical="true" android:layout_torightof="@+id/textview03" android:background="#ff0000" android:text="black" android:textcolor="#fff" /> android:id="@+id/textview05" android:layout_width="fill_parent" android:layout_alignparentbottom="true" android:background="#000" android:text="blue" android:textcolor="#fff" /> </RelativeLayout>

22. The following is an incomplete Android database application which is supposed to add, find and delete items from a local database. Examine the code (yes it's long) and complete the app by inserting the missing lines of code. Note: there are 10 places with missing lines. Each correct line is worth 1 mark. res/layouts/activity_database.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingbottom="@dimen/activity_vertical_margin" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" tools:context=".databaseactivity" > android:id="@+id/productid" android:layout_alignparenttop="true" android:layout_margintop="36dp" android:layout_torightof="@+id/button1" android:text="@string/product_id" /> <EditText android:id="@+id/productname" android:layout_alignright="@+id/button2" android:layout_below="@+id/productid" android:layout_margintop="40dp" android:text="@string/product_name"/> #1 <EditText android:id="@+id/productquantity" android:layout_alignleft="@+id/productname" android:layout_below="@+id/productname" android:layout_margintop="50dp" android:text="@string/product_quantity"/> <Button android:id="@+id/button1" #2 android:layout_alignparentbottom="true" android:layout_alignparentleft="true" android:onclick="newproduct" android:text="add" /> <Button android:id="@+id/button2" android:layout_alignbaseline="@+id/button1" android:layout_alignbottom="@+id/button1" android:layout_centerhorizontal="true" android:onclick="lookupproduct" android:text="find" />

<Button android:id="@+id/button3" android:onclick="removeproduct" android:layout_alignbaseline="@+id/button2" android:layout_alignbottom="@+id/button2" android:layout_alignparentright="true" android:layout_marginright="15dp" android:text="delete" /> </RelativeLayout> res/values/strings.xml <?xml version="1.0" encoding="utf-8"?> <resources> <string name="app_name">databaseactivity</string> <string name="action_settings">settings</string> <string name="product_name">product Name</string> <string name="product_id">product ID</string> #3 <string name="product_quantity">product Quantity</string> </resources> DatabaseActivity.java package com.example.databaseactivity; import android.os.bundle; import android.app.activity; import android.view.view; import android.widget.edittext; import android.widget.textview; public class DatabaseActivity extends Activity { TextView idview; EditText productbox; EditText quantitybox; @Override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_database); idview = (TextView) findviewbyid(r.id.productid); #4 productbox = (EditText) findviewbyid(r.id.productname); quantitybox = (EditText) findviewbyid(r.id.productquantity); public void newproduct (View view) { MyDBHandler dbhandler = new MyDBHandler(this, null, null, 1); int quantity = Integer.parseInt(quantityBox.getText().toString()); Product product = new Product(productBox.getText().toString(), quantity); dbhandler.addproduct(product); productbox.settext(""); quantitybox.settext("");

public void lookupproduct (View view) { MyDBHandler dbhandler = new MyDBHandler(this, null, null, 1); Product product = dbhandler.findproduct(productbox.gettext().tostring()); if (product!= null) { idview.settext(string.valueof(product.getid())); quantitybox.settext(string.valueof(product.getquantity())); else { idview.settext("no Match Found"); #5 public void removeproduct (View view) { MyDBHandler dbhandler = new MyDBHandler(this, null, null, 1); boolean result = dbhandler.deleteproduct( productbox.gettext().tostring()); if (result) { idview.settext("record Deleted"); productbox.settext(""); quantitybox.settext(""); else idview.settext("no Match Found"); MyDBHandler.java package com.example.databaseactivity; import android.content.contentvalues; import android.content.context; import android.database.cursor; import android.database.sqlite.sqlitedatabase; import android.database.sqlite.sqlitedatabase.cursorfactory; import android.database.sqlite.sqliteopenhelper; public class MyDBHandler extends SQLiteOpenHelper { private static final int DATABASE_VERSION = 1; private static final String DATABASE_NAME = "productdb.db"; private static final String TABLE_PRODUCTS = "products"; public static final String COLUMN_ID = "_id"; public static final String COLUMN_PRODUCTNAME = "productname"; public static final String COLUMN_QUANTITY = "quantity"; #6 public MyDBHandler(Context context, String name, CursorFactory factory, int version) { super(context, DATABASE_NAME, factory, DATABASE_VERSION); @Override public void oncreate(sqlitedatabase db) { String CREATE_PRODUCTS_TABLE = "CREATE TABLE " + TABLE_PRODUCTS + "(" + COLUMN_ID + " INTEGER PRIMARY KEY," + COLUMN_PRODUCTNAME + " TEXT," + COLUMN_QUANTITY + " INTEGER" + ")"; db.execsql(create_products_table); #7

@Override public void onupgrade(sqlitedatabase db, int oldversion, int newversion) { db.execsql("drop TABLE IF EXISTS " + TABLE_PRODUCTS); #8 oncreate(db); public void addproduct(product product) { ContentValues values = new ContentValues(); values.put(column_productname, product.getproductname()); values.put(column_quantity, product.getquantity()); SQLiteDatabase db = this.getwritabledatabase(); db.insert(table_products, null, values); db.close(); public Product findproduct(string productname) { String query = "Select * FROM " + TABLE_PRODUCTS + " WHERE " + COLUMN_PRODUCTNAME + " = \"" + productname + "\""; SQLiteDatabase db = this.getwritabledatabase(); Cursor cursor = db.rawquery(query, null); Product product = new Product(); if (cursor.movetofirst()) { cursor.movetofirst(); product.setid(integer.parseint(cursor.getstring(0))); product.setproductname(cursor.getstring(1)); product.setquantity(integer.parseint(cursor.getstring(2))); cursor.close(); else { product = null; db.close(); return product; public boolean deleteproduct(string productname) { boolean result = false; String query = "Select * FROM " + TABLE_PRODUCTS + " WHERE " + COLUMN_PRODUCTNAME + " = \"" + productname + "\""; SQLiteDatabase db = this.getwritabledatabase(); Cursor cursor = db.rawquery(query, null); #9 Product product = new Product(); if (cursor.movetofirst()) { product.setid(integer.parseint(cursor.getstring(0))); db.delete(table_products, COLUMN_ID + " =?", new String[] { String.valueOf(product.getID()) ); cursor.close(); result = true; db.close(); return result;

Product.java package com.example.databaseactivity; public class Product { private int _id; private String _productname; private int _quantity; public Product() { public Product(int id, String productname, int quantity) { this._id = id; this._productname = productname; this._quantity = quantity; public Product(String productname, int quantity) { this._productname = productname; this._quantity = quantity; public void setid(int id) { this._id = id; public int getid() { return this._id; #10 public void setproductname(string productname) { this._productname = productname; public String getproductname() { return this._productname; public void setquantity(int quantity) { this._quantity = quantity; public int getquantity() { return this._quantity;