Mobile Development Mid-Term Exam 2024 PDF
Document Details
Uploaded by FlexibleClimax
Mulungushi University
2024
Tags
Summary
This is a mobile development mid-term exam. The exam covers topics such as XML namespaces, Android layouts, Kotlin programming, and data passing between activities. It's for students learning Android development.
Full Transcript
Mobile Development Mid-Term Exam October 28, 2024 Mobile Development Mid-Term Exam Course: Mobile Development (Android with Kotlin) Duration: 2 hours Total Marks: 100 Section A: Multiple Choice Questions...
Mobile Development Mid-Term Exam October 28, 2024 Mobile Development Mid-Term Exam Course: Mobile Development (Android with Kotlin) Duration: 2 hours Total Marks: 100 Section A: Multiple Choice Questions (10 marks) 1. Which of the following is the correct way to declare an XML namespace in an Android layout file? (a) xmlns = ”http : //schemas.android.com/apk/res/android” (b) xmlns : android = ”http : //schemas.android.com/apk/res/android” (c) namespace = ”http : //schemas.android.com/apk/res/android” (d) xmlns : res = ”http : //schemas.android.com/apk/res/android” 2. What does the dp unit stand for in Android layout? (a) Display points (b) Density-independent pixels (c) Data points (d) Digital pixels 3. In Kotlin, which keyword is used to make a variable mutable? (a) const (b) val (c) var (d) mutable 4. Which layout is best suited for positioning elements in a grid-like fash- ion? (a) ConstraintLayout (b) LinearLayout (c) GridLayout (d) FrameLayout 5. Which of the following classes is used to store and manage UI-related data in a lifecycle-conscious way? (a) LifecycleObserver (b) ViewModel (c) DataBinding (d) LiveData Section B: Short Answer Questions (40 marks) 1. Kotlin Basics (8 marks) Explain the difference between val and var in Kotlin with examples. 2. Android Lifecycle (10 marks) Describe the Android activity lifecycle. Briefly explain each lifecycle method and its purpose. 3. Layouts (8 marks) Differentiate between ConstraintLayout and LinearLayout in An- droid. In which scenarios would you use each? 4. XML and UI Design (6 marks) Explain the purpose of match parent and wrap content in Android XML layouts. Give examples of when to use each. 5. Fragments (8 marks) What is a Fragment in Android, and why is it used? List at least two advantages of using Fragments. Section C: Coding Tasks (50 marks) 1. Activity and Intent (20 marks) Create an Android app with two activities: MainActivity and SecondActivity. In MainActivity, create a button labeled ”Go to Second Activity.” When the button is clicked, it should navigate to SecondActivity. Use an explicit intent for this task. 2 Define the button in activity main.xml. Add code in MainActivity.kt to handle the button click. SecondActivity should display a text message “Welcome to the Second Activity”. 2. UI Layout (15 marks) Design a user interface using XML that includes the following elements: A TextView to display the label ”User Information.” Two EditText fields for entering ”First Name” and ”Last Name.” A Button labeled ”Submit.” Align the TextView at the top center of the screen. Place the EditText fields one below the other in the center of the screen. Place the Button below the EditText fields. 3. Data Passing between Activities (15 marks) Extend the app from Question 1 to pass the user’s name from MainActivity to SecondActivity. In MainActivity, add an EditText for the user to enter their name. When the button is clicked, the name should be sent to SecondActivity and displayed there. Define an EditText in MainActivity for name input. Pass the inputted name from MainActivity to SecondActivity. Display the name in a TextView in SecondActivity. Bonus Question (Optional - 5 marks) Explain the concept of RecyclerView in Android. What advantages does it have over ListView, and why would you choose RecyclerView for displaying large data sets? 3