ANDROID PROGRAMMING EXAMINATION

CP 313 2022-2023


SECTION A: (40 MARKS)

Question One

Choose the most correct answer and write its letter in the answer booklet provided. (1 Mark Each)

i. All layout classes are the subclasses of: -

A. Android.widget

B. Android.view.View

C. Android.view.ViewGroup

D. Android.view.Widget


ii. What is manifest XML in android?

A. A file that contains all information about the layout of the android application.

B. A file that contains all the information about the android application.

C. A file that contains all the information about the activities of the android application.

D. A file that contains all resources of the android application.


iii. What is the use of a content provider in Android?

A. For sharing data between one activity and another activity.

B. For storing data in a SQLite database.

C. For sending data from one application to another application.

D. For storing data in a shared preferences.


iv. While developing android application developers can test their apps on: -

A. Emulators in android SDK.

B. Android phone.

C. Third-party emulator.

D. All of the above.


v. The services in android can be stopped using which of the following method?

A. system.exit() and stopService().

B. stopSelf() and stopService().

C. finish() and end().

D. serviceStop() and endService().


vi. Identify among the following which is not a state in the service lifecycle.

A. Running.

B. Start.

C. Paused.

D. Destroyed.


vii. Identify the dialogue class in Android among the following.

A. DatePicker.

B. AlertDialog.

C. ProgressDialog.

D. All of the above.


viii. What is the life cycle of broadcast receivers in android?

A. send intentO.

B. onReceive.

C. implicitBroadcastO.

D. sendBroadcastO, sendOrderBroadcastO, and sendStickyBroadcastO.


ix. What runs in the background and doesn’t have any UI components?

A. Intents.

B. Content Providers.

C. Services.

D. Applications.


x. Which one is not a nickname of a version of Android?

A. Cupcake.

B. Gingerbread.

C. Honeycomb.

D. Android.


Question Two

Write true if the statement is correct and false if the statement is incorrect.

(10 Marks - 1 Mark Each)

(a) Mobile Apps On Both Android And IOS Platforms Should Not Perform Long Lasting Tasks, Such As Network.


(b) Android is built upon the Java Micro Edition (J2ME) version of java.


(c) Native libraries is one of the core component of the .apk in android.


(d) The code which is compiled to run the android application is always contained within the xml layout file.


(e) The xml file that contains all the texts that your application uses is called text.xml.


(f) There is no guarantee that an activity will be stopped prior to being destroyed.


(g) In an explicit intent, the sender specifies the type of receiver.


(h) There can be only one running activity in a given time.


(i) Java is the only programming language used to make an android application.


(j) The only database that android application can work with is SQLite.


Question Three

(a) Assume you have a running application that is already running an Activity called Activity1. Activity1 starts another Activity called Activity2. Name one Activity lifecycle method that will be called on Activity1 after this point, but before Activity2 starts. (2 Marks)


(b) Suppose you have an application that is running an Activity called Activity1. Suppose that Activity1 executes and starts other Activities, but that the user never quits or backs out of the Activity. How many times can Activity1’s onCreate() method get called? (2 Marks)


(c) Suppose that there are two activities in an application named ActivityOne and ActivityTwo. You want to invoke ActivityTwo from ActivityOne. What code you will write? (3 Marks)


(d) How will you reference a textbox control in java file, that is available in XML file and the ID is txtName. (4 Marks)


(e) Suppose that there are two activities in an application named FirstActivity and SecondActivity. You want to send website name from ActivityOne to ActivityTwo. What code you will write? Suppose that website name is www.udom.ac.tz. (5 Marks)


(f) How will you get the data in secondActivity? Refer to part (e). (4 Marks)


SECTION B: (60 MARKS)

Attempt any THREE (3) out of FOUR (4) questions in this section.


Question Four

Many students now days fail to manage loan that they get from Higher Education Students Loan Board (HESLB). Most of them finish the money even before the period they are supposed to use. Based on the mentioned problem, HESLB wants a mobile application called Budget Planner that will helps their beneficiaries to manage their money. As a mobile apps developer, you have been consulted with HESLB to develop the Budget Planner mobile app that will do the following: receive the amount from the student (initial balance), the student will enter the number of days that he/she supposed to use the money. Every time the student spends a certain amount of money the app should deduct from the initial balance. Once the student is about to finishes the money, the app should alert him/her. The app should not allow the student to spend more than his/her initial balance.

(20 Marks)


Question Five

Currently, UDOM SACCOS have no tool to automate its operations as a result there is a delay in providing services to its customers. You have been asked by the management of UDOOM SACCOS to develop a mobile application that will store the information of its customers. The app should store name, college, age, gender and monthly contribution of its customers. The management want to show the reports of how customers are contributing monthly.

The management also wants to show the dates of different events within SACCOS such as the date of annual meeting etc. The management suggests the following features to be used: radio button for gender and spinner for college. Use progress bar to show the monthly contributions and calendar to show the dates of the events. Based on the given requirements, you found that the application has only two activities i.e. ActivityOne and ActivityTwo.

(20 Marks)


(a) Using the methods of Intent class show how you will send the customer’s data to the second activity. (5 Marks)


(b) Using the methods of Intent class show how you will receive the customer’s data within the second activity. (5 Marks)


(c) By the help of SQLiteOpenHelper class, show how you can save the customer’s details in a database. Use user and customer as the name of the database and table respectively. (10 Marks)


Question Six

The prime purpose of a content provider is to serve as a central repository of data where users can store and can fetch the data. The access of this repository is given to other applications also but in a safe manner in order to serve the different requirements of the user. Write an application that will allow users store their details such as name and phone numbers in a content provider. The application should also allow other applications to retrieve the stored user’s information. The application has one activity called MainActivity, two edit texts for name and phone number and two buttons for save data and view data. The ids for the views are etName, etPhoneNumber, btnSave and btnView.

(20 Marks)


Question Seven

Android Fragment represents a behavior or a portion of a user interface in an activity. Multiple fragments can be combined in a single activity to build a multi- panel User Interface (UI) and reuse a fragment in multiple activities. As a mobile apps developer, you have been asked to develop an application with two fragments named FragmentOne and FragmentTwo. When a user click on the specific fragment, the description of the fragment displays on the fragment container in the main activity which hosts the fragments. Assume the ids for FragmentOne and FragmentTwo are btnFragment_one and btnFragment_two respectively. Hint: use linear layout to create a fragment container.

(20 Marks)


END OF EXAMINATION PAPER