1 Spring 2017 (Thursday, March 9) Name: CS 4330/5390: Mobile Application Development Exam 1 This test has 8 questions and pages numbered 1 through 7. Reminders This test is closed-notes and closed-book. However, you are allowed to bring 1 page (8.5 X 11) of notes (both sides). Your notes must be your own, they must be hand written, and they must be turned in with your test. This test is to be done individually, and you are not to exchange or share materials such as the textbook and notes with other students during the test. If you need more space, use the back of a page. Note when you do that on the front. This test is timed. Your test will not be graded if you try to take more than the time allowed. Therefore, before you begin, please take a moment to look over the entire test so that you can budget your time. For program code, clarity is important; if your writings or code are sloppy and hard to read, you will lose points. Correct syntax also makes some difference. There are 100 points all. 1. (total 20 points) Short answers: multiple choice and fill-in-the-blank (a) (2 points) All Android apps have an automatically generated file named.java. It provides references (or resource Ids) to various resources used by the applications, e.g., layouts and drawables/mipmaps. That is, instead of hard coding such resources into an application, one externalizes and refers them by Ids. (b) (2 points) All the following layouts are supported by Android EXCEPT for: i. FrameLayout ii. GridLayout iii. GridBagLayout iv. LinearLayout v. RelativeLayout vi. TableLayout (c) (2 points) You use the view to provide visual feedback about some ongoing tasks, such as when you are performing a long-running task in the background. For example, you might be downloading some data from the Web and need to update the user about the status of the download. (d) (2 points) A represents a behavior or a portion of user interface in an activity. It is particularly useful in adapting a user experience across a wide range of devices, as they can be combined to build a multi-pane UI and be reused in multiple activities.
2 (e) (2 points) There are several framework methods to be called on various stages of an activity from its creation to destruction. This is the framework method where you initialize your activity. In this method you usually call the setcontentview() method to set the UI of your activity. i. oncreate() ii. onstart() iii. onrestart() iv. onresume (f) (2 points) In general, you use the startactivity() framework method to invoke an activity. However, it doesn t return a result from the called activity to the calling activity. If you need to pass data back from the called activity, you should instead use the () method to invoke it. (g) (2 points) As stated in the previous question, an activity can indicate its intention to receive a result when invoking another activity. However, to actually receive data from the called activity, you override the () method in the calling activity class. (h) (2 points) Android provides three different types of menus: options (actions/tools), context, and popup. Which type of menus is described below? It displays information related to a particular view of an activity. It is a floating menu owned by or associated with a view. Its menu items can be defined statically in an XML resource file or programmatically in source code. It can be activated by any UI event such as button click. (i) (2 points) To provide the options (actions/tools) menu for your activity, you need to override two framework methods in your activity: oncreateoptionsmenu() and. The first method is called to populate a menu with menu items, and the second method is called when a menu item is selected. (j) (2 points) A fragment has its own lifecycle. Which of the following lifecycle methods is not one of those that are most commonly overridden in a fragment class? i. onattach() ii. oncreate() iii. oncreateview() iv. onpause()
3 2. (4 points) One of the noticeable features of Android programming is the use of XML. List at least four different uses of XML. 3. (5 points) There are several different units of measurement that you can use to specify the size or dimension of an Android UI element. Which unit is recommended for specifying the size of a view? Justify your answer by stating the reason. 4. (6 points) Describe the difference between explicit and implicit intents. Do not use the terms explicit and implicit in your description. 5. (5 points) The term adaptive design refers to the adaptation of a layout design that fits an individual screen size and/or orientation. It is important to Android because it supports flexibility when designing an app that can work on multiple devices. Describe briefly the Android approach for providing several alternative layouts to target different screen configurations (e.g., sizes)..
4 6. (total 25 points) You are to develop a login component of some Android app. You will be writing it incrementally by completing given skeletal code. (a) (10 points) Let s first define its UI the login screen of the app by completing the skeletal activity main.xml file give below. As shown below, the login UI consists of only a few views. You may need to specify their attributes (e.g., android:id) to refer to them in your activity class (see Problem 6b below). For layouts, use only the LinearLayout class; you are not allowed to use any other layout classes. <!-- activity_main.xml --> <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <!-- WRITE YOUR CODE HERE! --> </LinearLayout>
5 (b) (15 points) Next, let s code the logic of the login component handling a login request by checking the user name. When the login button is clicked, the app checks if the provided user name is known to the system. If that s the case, it will show a welcome toast message (see a sample screen below); otherwise, the login request is ignored, i.e., nothing happens. Use the given LoginManager class to check the validity of a user name. Hint: you need to define only one or two methods, including the oncreate() method. public class MainActivity extends Activity { private static class LoginManager { /** Is the given user name known to the system? */ public boolean isknownuser(string name) {... } } private void toast(string msg) { Toast.makeText(this, msg, Toast.LENGTH_SHORT).show(); } <!-- WRITE YOUR CODE HERE! --> }
6 7. (20 points) Here you are to modularize the login app of the previous problem by separating the logic of checking a user name and that of welcoming a user (see below for an improved UI). For this, you will be creating a new activity named WelcomeActivity. This activity is to be invoked by the main activity and to show a welcome toast message. (a) Change the code of MainActivity to invoke the WelcomeActivity class when a user is successfully logged in. You should pass the user name to the WelcomeActivity class. Assume that the following definition is already included in the AndroidManifest.xml file. <activity android:name=".welcomeactivity" android:label="@string/welcome" > <intent-filter> <action android:name="edu.utep.cs.cs4330.exam1.welcome" /> <category android:name="android.intent.category.default" /> </intent-filter> </activity> (b) Define the WelcomeActivity class to show a welcome toast message. Don t worry about its UI other than the toast message. Hint: you need to define/override only one method.
7 8. (15 points) Let s reconsider the login app of the previous problem. Let s improve its user experience by providing a different UI depending on the screen orientation. That is, you will be providing a new UI for the landscape mode (see the sample screen below). All the views of the UI form a single row. Both the name label and the login button have natural widths, and the edit widget in the middle has all the remaining space. Describe your approach for providing two different UIs, one for the portrait mode and the other for the landscape. Define the UI for the landscape mode by being specific about its full pathname (directory and file names). As before, use only the LinearLayout class for layouts.