MAD final exam Flashcards

1
Q

Define the following terms related to mobile app development:
i. APK
ii. SDK
iii. UI/UX

A

APK = android package kit/android application package. a file format used to install applications on android devices. consists of (Manifest file, resources(images, XML layout files), Dalvik(runs application

SDK= Software development kit. collection of tools and libraries and documentation used to build apps for a specific platform.

User interface/ User Experience. design ad functionality of an app that affects how users interact with it

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
  1. Discuss the purpose of AndroidManifest file and its further details. 9. Draw a skeletal structure of this file.
A

crucial file bcz it serves a configuration file for the app. proovides essential info to the android system.

declares app components. activities, services, broadcast receivers and content providers.

sets permission. sprcific permision are so dat the app needs to acess system features or user data.

declare intents and filters. defines intents and filters for communication components within the app and other apps.

specify app icon and name. as its set they appear in the app launcher.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Differentiate between Java and Kotlin in Android development. What are the advantages of using
Kotlin?

A

kotlin is interoperability(coexist with java in aandroid projects),

builtin null safety to prevent null ponter exceptions while java’s null safety requires explicit null checks

kotlin is newer

advantages

-enhanced cod readability(easy to understand and maintain)
better null safety
-reduced bolierplate code(less repetitive code = fewer errors and faster development)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

List and briefly describe the four main components of an Android application. Provide an example
use case for each component.

A

activities. represents a single screen within an app e.g login screen

services. runs in background , performs long-running tasks. e.g music player service , location tracking service

broadcast receivers. respond to system wide or application specific events e.g incoming calls , battery status reciever.

content providers. manges and persists data that can be shared by multiple apps. e,g contact list provider.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the purpose of an Intent in Android? Explain the difference between an explicit intent and
an implicit intent

A

message passing mechanism . it communicates between components within an app or between different apps.

explicit intents. directly specify the target component( e.g activity, service) by its class name. used for internal communication within an app or to start specific components in other apps.

implicit. specify the action to be performed and the data to be used. allows other apps to to handle the intent if they have the appropiate filters. used to open web pages , send emails , amke calls

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How does the Android activity lifecycle work? List and briefly explain the key lifecycle methods of
an Android activity.

A

onCreate():
Called when the activity is first created.
onStart(): Called when the activity becomes visible to the user.
onResume(): Called when the activity starts interacting with the user.
onPause(): Called when another activity is about to take focus.
onStop(): Called when the activity is no longer visible to the user.
onDestroy(): Called when the activity is being destroyed.
onRestart(): Called when the activity is being restarted after having been stopped.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Describe the role of a content provider in Android. Provide an example scenario where a content
provider would be useful

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is RecyclerView, and why is it commonly used in Android app development? Provide a code
example of implementing a simple RecyclerView.

A

RecyclerView is a versatile view in Android used for displaying large lists of data efficiently. It recycles views that scroll off the screen, improving performance and reducing memory usage.

//check the slides

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Explain the concept of threading and concurrency in Android. Why is it important, and what are
some methods to achieve multithreading in Android apps?

A

Threading in Android allows multiple threads to run concurrently, enabling tasks to be performed in the background without blocking the main UI thread.

Concurrency is the ability of an application to perform multiple operations simultaneously.

Importance:

Threading is crucial for maintaining a responsive user interface and ensuring that time-consuming tasks (like network operations or database access) do not freeze the app.
Methods to achieve multithreading in Android:

AsyncTask: Simplifies background operations and updates the UI.
Handler: Allows communication between threads and the main UI thread.
Executors: Provides a high-level API for managing threads and task execution.
Coroutines: A modern approach for asynchronous programming that simplifies code and improves readability.

Using these methods helps improve app performance and user experience.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Briefly discuss the Model-View-Controller (MVC) architectural pattern and its relevance in Android
development. Provide an example of how MVC can be implemented in an Android app.

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
  1. Draw an android stack overview and label it fully (revise session 4a and session 3a)
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q
  1. Explain the Linux and Native layers of the Android Architecture Stack (session 4a and 3a)
A

Linux Layer:
The Linux layer serves as the foundation of the Android architecture, providing essential services such as hardware abstraction, process management, memory management, and security features. It includes the Linux kernel, which interfaces directly with the hardware and manages system resources.

Native Layer:
The Native layer consists of C/C++ libraries that provide core functionalities for Android apps, including graphics (Skia), database management (SQLite), and web rendering (WebKit). This layer allows developers to access lower-level hardware features and optimize performance for resource-intensive applications.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q
  1. Discuss Virus, Malware and Spyware, explain why they would affect android apps.
A

Virus: A malicious program that replicates itself and spreads to other devices, potentially damaging files or systems.

Malware: A broad term for any malicious software designed to harm or exploit devices, data, or networks (includes viruses, ransomware, etc.).

Spyware: A type of malware that secretly monitors user activity and steals personal information.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q
  1. Discuss why we would use a native platform to develop android applications.
A

Optimal Performance: Native apps have direct access to device hardware, providing faster and more efficient performance.
Full Access to Features: Native development allows access to all Android features (camera, sensors, etc.) and APIs.
Better User Experience: Native apps integrate seamlessly with the Android system, ensuring smoother UI and UX.
Security: Native platforms provide robust security features and updates for Android apps.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q
  1. What similarities and differences are there between Windows and Android architectures.? 6. Draw well labeled diagrams to differentiate the two.
A

Similarities:

Layered Architecture: Both Windows and Android have layered architectures, with hardware at the bottom and applications at the top.
Kernel: Both use a kernel for core system services (Android uses Linux, while Windows uses the Windows NT kernel).
User Interface: Both provide a GUI for user interaction with applications.
Security: Both have built-in security features like access control and user permissions.

Differences:

Kernel: Android uses the Linux kernel, while Windows uses the Windows NT kernel.
Application Framework: Android uses a Java-based application framework, while Windows apps are built using various technologies (e.g., .NET, C++).
User Interaction: Android is optimized for touch-based interaction, while Windows traditionally supports both touch and desktop-based interactions.
App Distribution: Android apps are distributed through the Google Play Store, while Windows apps are distributed via the Microsoft Store and other sources.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q
  1. Discuss the key features of Android studio that you find useful for application development.
A

Intelligent Code Editor: Provides code suggestions, error checking, and refactoring tools.
Layout Editor: Drag-and-drop interface for designing UI components with real-time previews.
Gradle Build System: Manages project dependencies, builds, and APK generation.
Emulator: Allows testing apps on virtual devices without needing physical hardware.
Debugging Tools: Advanced tools like the debugger, logcat, and profiler for troubleshooting and optimizing performance.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q
  1. List and discuss any 5 Resource files found in the android app file structure.
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q
  1. Differentiate between a class and an object in Kotlin, use sample codes for further elaboration of your understanding.
A

a class in a blueprint of a class while an object is an instance of a class.

class Car(val model: String, val year: Int) {
fun start() = println(“$model is starting.”)
}

// Creating an instance (object) of the class
val car = Car(“Toyota”, 2020)
car.start() // Output: Toyota is starting.
——————————————————————————————————————————–

object MySingleton {
val name = “SingletonObject”
fun display() = println(“This is a singleton object.”)
}

// Accessing singleton object
MySingleton.display() // Output: This is a singleton object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q
  1. What is an Activity? Draw an activity lifecycle diagram and main methods and different life stages. (Session 4b)
A

-Preserve user data and state if:
User temporarily leaves app and then returns
User is interrupted (for example, a phone call)
User rotates device
-Avoid memory leaks and app crashes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q
  1. Show how a constructor is created in Kotlin class, show a constructor with parameters and no parameters
A

Primary Constructor (with parameters):
class Person(val name: String, val age: Int)

Secondary Constructor (no parameters):
class Person {
constructor() {
println(“No-argument constructor”)
}
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What is the purpose of the initializer block? Show code which implements it.

A

initializer block in Kotlin is used to execute code when an instance of a class is created, especially for complex initialization.

class Person(val name: String) {
init {
println(“Person’s name is $name”)
}
}

val person = Person(“Alice”) // Output: Person’s name is Alice

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q
  1. How do we show properties in an android class, show with an example
A

properties in a class are defined using variables. class User(val name: String, var age: Int)

val user = User(“John”, 25)
println(user.name) // Access property ‘name’
user.age = 26 // Modify property ‘age’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q
  1. How do show inheritance in a Kotlin, demonstrate with sample code
A

inheritance is shown using the open keyword for the base class and : for subclassing.

open class Animal {
fun eat() = println(“Eating”)
}

class Dog : Animal() {
fun bark() = println(“Barking”)
}

val dog = Dog()
dog.eat() // Inherited method
dog.bark() // Dog’s own method

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q
  1. Give examples of classes found in Kotlin show with sample how to implement the classes.
A

data class.use data keyword. generates getters for each property
data class Player(val name: String, val score: Int)

Pair and Triple. are predefined data classes that store 2 or 3 pieces of data respectively.
val bookAuthor = Pair(“Harry Potter”, “J.K. Rowling”)
println(bookAuthor)
=> (Harry Potter, J.K. Rowling)

val bookAuthorYear = Triple(“Harry Potter”, “J.K. Rowling”, 1997)
println(bookAuthorYear)
println(bookAuthorYear.third)
=> (Harry Potter, J.K. Rowling, 1997)
1997

enum class. user defined data type for a set of named values. enum keyword.
enum class Color(val r: Int, val g: Int, val b: Int) {
RED(255, 0, 0), GREEN(0, 255, 0), BLUE(0, 0, 255)
}

object /singleton. used for one instance of a class to ever exist.

object Calculator {
fun add(n1: Int, n2: Int): Int {
return n1 + n2
}
}

24
Q
  1. What are functions in Kotlin, demonstrate with sample code how we implement a function?
A

a block of code that performs a specific task.
fun keyword

fun printHello() {
println(“Hello World”)
}

25
Q
  1. How many types of function parameters are found in Kotlin, state and give example code of each.
A

named arguments
required parameters
default parameters

26
Q
  1. What is a lambda function?
A

a function without a name

val sum = { a: Int, b: Int -> a + b }
println(sum(3, 4)) // Output: 7

27
Q
  1. How do we use filters in functions, demonstrate with sample code.
A

Eager Filter: process all elements immediately and return a new collection.

Lazy filters use sequences, evaluating elements only when needed.

28
Q
  1. What’s the difference between a mutable and immutable variable? Declare them.
A

mutable is a variable that can be changed. declared with var keyword.

immutable : variable is constant. declared with val keyword.

29
Q

List and demonstrate different ways Kotlin implement conditionals.

A

if else:
val number = 10
if (number > 0) {
println(“Positive”)
} else if (number < 0) {
println(“Negative”)
} else {
println(“Zero”)
}

when statements:
val color = “Red”
when (color) {
“Red” -> println(“Stop”)
“Green” -> println(“Go”)
“Yellow” -> println(“Caution”)
else -> println(“Unknown Color”)
}

30
Q
  1. Demonstrate how to use when, range, for loop, while loop, repeat loop, demonstrate with examples.
A

when
val x = 2
when (x) {
1 -> println(“One”)
2 -> println(“Two”)
else -> println(“Other”)
}

range & for loop
for (i in 1..5) {
println(i) // Prints 1 to 5
}

while
var i = 1
while (i <= 5) {
println(i)
i++
}

repeat
repeat(5) {
println(“Hello”) // Prints “Hello” 5 times
}

31
Q
  1. Demonstrate how you implement an array, and a list, how do they differ.
A

Array: Fixed size, can store both primitive and reference types.

val numbers = arrayOf(1, 2, 3, 4, 5)

List: Dynamic size (modifiable with mutable lists), typically used for reference types, and has additional methods for collection operations.

val numbers = listOf(1, 2, 3, 4, 5)

32
Q
  1. What is Null safety and how do we test for it?
A

Null safety in Kotlin ensures that variables cannot hold a null value unless explicitly allowed. To test for null, use the safe call operator (?.)

e.g
val name: String? = null
println(name?.length) // Safe call

33
Q
  1. What is an intent? And its purpose (session. 6)
A

requests an action from another app component , such as another activity.

explicit intent. fufills a request using a specific component. it also navigates internally to an activity in your app.

implicit intent. provides a generic action the app can perform.resolved using mapping of the data type and action to known components.

34
Q
  1. Implement with a code snippet an Intent for reading an email
A

val intent = Intent(Intent.ACTION_SENDTO).apply {
data = Uri.parse(“mailto:example@example.com”)
}
startActivity(intent)

35
Q

Show how to create an Options menu with xml code

A

XML for the menu (res/menu/menu_main.xml):

<menu>
<item></item>
</menu>

Inflate menu in activity (MainActivity.kt):
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
menuInflater.inflate(R.menu.menu_main, menu)
return true
}
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
menuInflater.inflate(R.menu.menu_main, menu)
return true
}

36
Q
  1. Describe activity states and relevant callback methods for each state (session 7)
A

onCreate() - activity is being initialized
onStart() - visible to user
onResume() - has input focus
onPause() - doesnt have input focus
onStop() - no longer visible
onDestroy() - activity is destroyed

37
Q
  1. Explain with sample code all callback methods
A

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    // Initialize activity
}

override fun onStart() {
    super.onStart()
    // Activity visible
}

override fun onResume() {
    super.onResume()
    // Activity interacting with the user
}

override fun onPause() {
    super.onPause()
    // Activity partially obscured
}

override fun onStop() {
    super.onStop()
    // Activity no longer visible
}

override fun onDestroy() {
    super.onDestroy()
    // Clean up activity
}

override fun onRestart() {
    super.onRestart()
    // Activity restarting
} }
38
Q

explain the Fragment lifecycle

A

Fragment is added
onAttach()
onCreate()
onCreateView()
onViewCreated()
onStart()
onResume()
Fragment is Active
onPause()
onStop()
onDestroyView()
onDestroy()
onDetach()
Fragment is destroyed

39
Q
  1. How do you apply a theme to an activity
A

To apply a theme to an activity, specify the theme in the AndroidManifest.xml file using the android:theme attribute within the <activity> tag.</activity>

40
Q
  1. Explain the Resource directories contents
A

each resource has a resource id

Android autogenerates a class file named R.java with references to all resources in the app.

R.<resource_type>.<resource_name></resource_name></resource_type>

R.drawable.ic_launcher (res/drawable/ic_launcher.xml)

Individual views can also have resource IDs.

e.g of res directories.
drawable
layout
mipmap
values

drawable: Contains images and graphic resources (e.g., PNG, JPG, XML for shapes).

layout: Holds XML files defining UI layouts.

mipmap: Stores launcher icons for different screen densities.

values: Includes XML files for resources like strings, colors, dimensions, and styles.

41
Q

d. State and explain the benefits of having a good app architecture

A
42
Q

c. Write a simple XML code for a constraintlayout with a TextView in it. [10 marks]

A
43
Q

b. What is a constraintLayout? What advantage does it bring to views and viewGroups than other layouts? [3 marks]

A
44
Q

b. Explain the difference between ART and Dalvik

A
45
Q

Android uses a collection of packages which Is a group of related predefined classes. Name any three of such packages

A
46
Q

a. What is material design in Android development. [4 Marks]

A

Adaptable system of guidelines, components, and tools that support best practices for UI design.

47
Q

b. State and explain any 6 material components libraries provided by Android and design guideline.

A

Text fields
Buttons
Menus
Cards
Snackbar
Floating Action Button (FAB)
App bars (top and bottom)
Navigation Drawer

48
Q

c. Explain the concept of Localize you App. [6 Marks]

A

● Separate the localized aspects of your app (for example, text, audio files, currency, and numbers) as much as possible from the core Kotlin functionality of the app.
● When a user runs your app, the Android system selects which resources to load based on the device’s locale.
● If locale-specific resources are not found, Android falls back to default resources you defined.

49
Q

d. With the aid of a code example, localize an app language to ‘US’ and country to ‘es”. [6 marks]

A

layout-b+en+US values -b+es

50
Q

e. explain a coordinatorLayout. [3 Marks]

A

● Acts as top-level container in an app
● Manages interaction of its child views, such as gestures
● Recommended for use with views like a Snackbar or FAB

51
Q

b. You are working on a Kotlin programming assignment where you need to manage a list of student names. You decide to use an array for this purpose.

i. Demonstrate how to create an array of student names using the arrayOf() function. Provide a code example that creates an array containing the names of three students. Make use of comments in your code. [5 marks]

fun main() { 1 mark for function declaration
// Create an array of student names using arrayOf() 1 mark for use of comments
val studentNames = arrayOf(“Alice”, “Bob”, “Charlie”) 3 marks for array declaration with three variables.
}

ii. Iterate through the array in b(i) above to print each student’s name. [3 marks]

// Iterate through the array and print each student's name
for (name in studentNames) { 	3 marks for correct use of iteration construct.
    println(name)
}
A
52
Q

i. Mathematical operators [2 marks]
ANS +, -, *, /, % full marks for all 5 symbols
ii. Comparison operators [2 marks]
ANS < <= > >= full marks for all 4 symbols

A
53
Q

e. Assign an Int to a Byte on the code below. What is the expected out? [2 marks]

val i : Int = 6
val b : Byte = i
printLn(b)

A

compilation error because Kotlin doesn’t allow implicit conversions from Int to Byte. You need to explicitly convert Int to Byte using the .toByte() method.

val i: Int = 6
val b: Byte = i.toByte()
println(b) // Output: 6

54
Q

f. Write a for loop code snippet to print out the following strings from an array. [3 marks]

A
55
Q

d. State and explain the benefits of having a good app architecture [6 Marks]

A
56
Q

e. State and explain the android styling system benefits [4 Marks]

A
57
Q

e. Write a code snippet to join the two arrays below. Print the contents [6 Marks]

val numbers = intArrayOf(1,2,3)
val numbers2 = intArrayOf(4,5,6)

A
58
Q

i. With the aid of an example what is a string in kotlin? [3 marks]

ii. What is a string template? Show with 2 examples [4 marks]

A