0% found this document useful (0 votes)
2 views

Kotlin-and-Android-From-Scratch

The document provides a comprehensive overview of Kotlin programming and Android development concepts, including definitions of programming terms, function creation, and the use of Android Studio. It covers various topics such as class inheritance, data types, and the purpose of specific files in Android projects. Additionally, it includes questions and answers related to these topics to facilitate learning.

Uploaded by

Anh Pham
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Kotlin-and-Android-From-Scratch

The document provides a comprehensive overview of Kotlin programming and Android development concepts, including definitions of programming terms, function creation, and the use of Android Studio. It covers various topics such as class inheritance, data types, and the purpose of specific files in Android projects. Additionally, it includes questions and answers related to these topics to facilitate learning.

Uploaded by

Anh Pham
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

Kotlin and Android From Scratch

HÍc trñc tuy¿n t¡i https://quizlet.com/_9fbly5

1. What is a program A series of instruc-


tions that a com-
- A specific task puter system ex-
- A tool that helps you write Kotlin code ecutes to accom-
- A series of instructions that a computer system plish some action
executes to accomplish some action
- A defined set of instructions that tells your computer
to print "Happy Birthday!"

2. Which keyword do you use to define a function in fun


Kotlin?

- fun
- func
- function
- newFunction
- main

3. Which of the following do you need to create a Kotlin - a main() function


program that prints a line of text? (choose as many - curly braces {}
answers as you see fit) around the instruc-
tions to the system
- comment describing what your program does - a call to print() or
- a main() function println()
- curly braces {} around the instructions to the system - a piece of
- a call to print() or println() text surrounded by
- a piece of text surrounded by quotation marks quotation marks

4. What do you expect this Kotlin code to do? Print two lines of
text
fun main(args: Array<String>) {
println("Hello, world!")
println("It's a sunny and warm day!")
}

- Print one line of text


- Print two lines of text
- Print three lines of text
- Print two lines of text seperated by a blank line
1 / 26
Kotlin and Android From Scratch
HÍc trñc tuy¿n t¡i https://quizlet.com/_9fbly5

5. How would you modify this main() function so that it Set val age to 4,
prints a 6-layer cake for someone's 4th birthday? set val layers to 6

fun main() {
val age = 24
val layers = 5
printCakeCandles(age)
printCakeTop(age)
printCakeBottom(age, layers)
}

- Set val age to 6, set val layers to 4


- Set val age to "4", set val layers to "6"
- Set val age to 4, set val layers to 6
- Leave the code as-is

6. Which of these options correctly calls the function, createMes-


below, and passes it valid input arguments? sage("Amy",
"Australia", 20)
fun createMessage(name: String,
location: String,
age: Int) {
println("My name is ${name}. I am from ${location},
and I am ${age} years old.")
}

- createMessage("Amy", "Australia", 20)


- createMessage("Evan", England, 9)
- createmessage("Tom", "Thailand", "40")
- createMessage(Heather, "Haiti", 7)

7. What does IDE stand for? Integrated Devel-


opment Environ-
- Integrated Development Environment ment
- Independent Design Environment
- Ideal Developer Environment
- Intelligent Design Environment

8.
2 / 26
Kotlin and Android From Scratch
HÍc trñc tuy¿n t¡i https://quizlet.com/_9fbly5
Which of the following are advantages of using An- - It can help pre-
droid Studio? (Choose as many as you seem fit) vent typos and oth-
er mistakes in your
- It can help prevent typos and other mistakes in your code.
code. - It comes with
- It comes with a virtual device called an emulator that a virtual device
can run your app. called an emulator
- It can show you a real-time preview of how your app that can run your
will look on-screen while you code. app.
- It can automatically translate your app into other - It can show you a
languages. real-time preview
of how your app
will look on-screen
while you code.

9. What does "Minimum SDK" refer to in an Android The minimum ver-


Studio project? sion of Android
that your app can
- The minimum amount of storage that your app re- run on
quires for download
- The minimum number of devices that your app can
access
- The minimum download speed that your app requires
- The minimum version of Android that your app can
run on

10. What is the purpose of using a virtual device, or emu- To test your app on
lator, in Android Studio? a device without
having that physi-
- To show a variety of error messages to users cal device
- To experiment with app code safely
- To test your app on a device without having that
physical device
- To see what your app looks like in a web browser

11. In Android Studio, what is a project template good for? - It makes getting
(Choose as many answers as you see fit) started on building
a new app faster.
- It causes Android Studio to download files faster. - It provides a

3 / 26
Kotlin and Android From Scratch
HÍc trñc tuy¿n t¡i https://quizlet.com/_9fbly5
- It makes getting started on building a new app faster. structure that fol-
- It provides a structure that follows best practices. lows best prac-
- It is the only way to build apps that can be previewed tices.
in Android Studio. - It makes build-
- It makes building a new app less error-prone by ing a new app
pre-populating the project with some app code. less error-prone by
pre-populating the
project with some
app code.

12. How do you create a new project in Android Studio? Both B and C are
ways to create a
- A. Log out of Android Studio, and navigate to your new project in An-
project folder to find instructions. droid Studio.
- B. If you have a project already open, select File > Correct!
New > New Project from the Android Studio menu.
- C. In the "Welcome to Android Studio" window, click
"Start a new Android Studio project."
- D. Create a new file on your computer, and title it
"New Android Studio Project."
- Both B and C are ways to create a new project in
Android Studio.
Correct!
- None of the above

13. Which of the following elements is considered a View All of the above
in an Android app?

- An image
- A clickable button
- Text on the screen
- All of the above
- None of the above

14. What is the main purpose of a ViewGroup? It serves as a con-


tainer for View ob-
- It groups together the most common views that de- jects, and is re-
velopers use in Android apps. sponsible for ar-
- It serves as a container for View objects, and is

4 / 26
Kotlin and Android From Scratch
HÍc trñc tuy¿n t¡i https://quizlet.com/_9fbly5
responsible for arranging the View objects within it. ranging the View
- It is required to make a view interactive as a way to objects within it.
group TextViews on a screen.
- It is required to set colors and background images.

15. The type of ViewGroup that helps you arrange the ConstraintLayout
views inside of it in a flexible way is called a

16. Which of the following are Attributes in Android? - text


(Choose as many answers as you see fit) - textSize
- textColor
- text
- textSize
- textUse
- textColor
- textContent

17. In Android, a graphic that can be drawn to the screen Drawable


is generally referred to as a

18. Which of the following is an example of a "constraint" - A view that


that could be applied to a view in a ConstraintLayout must always be
ViewGroup in the Layout Editor? (Choose as many a minimum dis-
answers as you see fit) tance away from
the edge of its con-
- A view that must always be a minimum distance away tainer
from the edge of its container - A view that must
- A view that must always be free of warning triangles always be to the
- A view that must always be to the right of another right of another
view view
- A view that must always be the topmost view inside - A view that must
a container always be the top-
- A view that must always include a contentDescrip- most view inside a
tion attribute container

19. What is the purpose of the activity_main.xml file in the It describes the
project you created? layout of view
groups and views
- It provides the theme settings for your app for a screen.
- It lets your app users create their own custom views
5 / 26
Kotlin and Android From Scratch
HÍc trñc tuy¿n t¡i https://quizlet.com/_9fbly5
of the app
- It stores all the images your app will use
- It describes the layout of view groups and views for
a screen

20. Why should you use string resources instead of - It makes your app
hard-coded strings in your apps? (Choose as many easier to translate.
answers as you see fit) - It allows you to
reuse the same
- It makes your app easier to translate string in multiple
- It allows you to use longer strings in your app places in your pro-
- It allows you to apply special color attributes to your gram.
string
- It allows you to reuse the same string in multiple
places in your program

21. Which of the following is an example of a class? - A Car class that


(Choose as many answers as you see fit) has a make and
model, and that
- A Car class that has a make and model, and that can can be driven
be driven - A Flower class
- A Flower class that has a scent that has a scent
- A Puppy class that has breed, weight and age, and - A Puppy class
that can bark that has breed,
- A ShoppingCart class that has a cart size and cart weight and age,
value, and that can hold items and that can bark
- A Song class that has lyrics - A ShoppingCart
- None of these are examples of a class. class that has a
cart size and cart
value, and that can
hold items
- A Song class that
has lyrics

22. Which of the following is a difference between a class - You can think of
and an instance? (Choose as many answers as you a class as a blue-
see fit) print and an in-
stance as the actu-
- You can think of a class as a blueprint and an in- al "thing".

6 / 26
Kotlin and Android From Scratch
HÍc trñc tuy¿n t¡i https://quizlet.com/_9fbly5
stance as the actual "thing". - A class is like
- A class is like architectural plans for a bridge, and architectural plans
the Golden Gate bridge an instance of those plans. for a bridge, and
- A class is for defining categories of "things", while the Golden Gate
instances are for defining their properties. bridge an instance
- You can create multiple instances from a class, but of those plans.
you can't create classes from instances. - You can create
multiple instances
from a class, but
you can't create
classes from in-
stances.

23. Class or Instance? Class

Information about properties shared by all "things"


belonging to the class, such as number of sides, num-
ber of legs, or that it has a color.

24. Class or Instance? Instance

The specifics about a property, such as the specific


color of a "thing" that can have a color.

25. True or false? False

Every MainActivity class in Android must have a


main() function.

26. Which of the following is NOT a way for creating a - Use // to turn the
comment in Kotlin? (Choose as many answers as you rest of a function
see fit) into a comment.
- Use /* to start
- Add // at the beginning of or inside a line and any- a comment that is
thing after that // is considered a comment. one line long.
- Put /* or /** to start a block comment, and end it with
*/.
- Use // to turn the rest of a function into a comment.
- Use /* to start a comment that is one line long.

7 / 26
Kotlin and Android From Scratch
HÍc trñc tuy¿n t¡i https://quizlet.com/_9fbly5
27. Which of the following statements about a conditional - A conditional
statement is true? (Choose as many answers as you statement is a way
see fit) for you to set up a
condition and en-
- A conditional statement is a way for you to set up sure that code fol-
a condition and ensure that code following it is only lowing it is only ex-
executed if that condition is met. ecuted if that con-
- A conditional statement does not require any key- dition is met.
words. - A conditional
- A conditional statement should only be used with statement can be
integers as input. used within func-
- A conditional statement can be used within func- tions to return out-
tions to return output based on conditions defined in put based on con-
that function. ditions defined in
that function.

28. What is a good reason for you to add comments to All of the Above
your code?

- To explain to yourself or others why the code is


written a certain way.
- To structure code, like chapter headings in books
- To point out some part of the code that is very impor-
tant
- To explain to other developers how to use your code
for their own programs
- All of the above
- None of the above

29. Which of the following are Kotlin data types? (Choose - IntRange
as many answers as you see fit) - Int
- Boolean (true or
- IntRange false)
- Num
- Int
- Boolean (true or false)

30. Which of the following are valid keywords used in -if, else
conditional statements in Kotlin? (Choose as many -when

8 / 26
Kotlin and Android From Scratch
HÍc trñc tuy¿n t¡i https://quizlet.com/_9fbly5
answers as you see fit)

- if, else
- if, then, stop
- when
- repeat, finish

31. Which of the following is true about class inheri- All of the Above
tance?

- Class inheritance lets you reuse code and makes


your program easier to maintain.
- Properties and functions of the parent class(es) are
available to the child class.
- You can define additional properties and functions
that are specific to subclasses.
- You can override parent class members in subclass-
es.
- All of the above

32. Which of the following are true about abstract class- - They can be
es? (Choose as many answers as you see fit) extended by sub-
classes and imple-
- They can be extended by subclasses and implemen- mentations can be
tations can be provided for abstract members of the provided for ab-
class. stract members of
- They have an implementation for all of their proper- the class.
ties and functions. - They may have
- They may have abstract properties or abstract func- abstract proper-
tions. ties or abstract
- They can be instantiated. functions.
- They are not fully implemented and cannot be instan- - They are not fully
tiated. implemented and
- They need to be marked with the open keyword to be cannot be instanti-
extended. ated.

33. The ________ is called when you create an instance of Constructor


a class.

34.
9 / 26
Kotlin and Android From Scratch
HÍc trñc tuy¿n t¡i https://quizlet.com/_9fbly5
How do you mark a property to be used only inside its Use the private
current class? keyword

- Use the override keyword.


- Use the val keyword.
- Use the private keyword.
- Use the closed keyword.
- It is not possible to do this.

35. Select all answers that are true for this XML layout - The starting edge
when displayed on the screen. (You can sketch this of TextView A is
out on a piece of paper first, if that helps.) aligned to the
<androidx.constraintlayout.widget.ConstraintLayout starting edge of
android:layout_width="match_parent"android:lay- the parent view.
out_height="match_parent"><TextView - The tops of
android:id="@+id/textViewA" TextView A and
android:layout_width="wrap_content"android:lay- TextView B are
out_height="wrap_content"android:text="A" aligned to top of
app:layout_constraintStart_toStartOf="parent" the parent view.
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textViewB"
android:layout_width="wrap_content"android:lay-
out_height="wrap_content"android:text="B"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLay-
out>

(Choose as many answers as you see fit)


- TextView A appears vertically stacked on top of
TextView B.
- The starting edge of TextView A is aligned to the
starting edge of the parent view.
- The starting edge of TextView B is aligned to the
starting edge of the parent view.
- TextView B is horizontally and vertically centered
within the parent.
- The tops of TextView A and TextView B are aligned to
10 / 26
Kotlin and Android From Scratch
HÍc trñc tuy¿n t¡i https://quizlet.com/_9fbly5
top of the parent view.
- The width of TextView A matches the width of the
parent ConstraintLayout.

36. Which line(s) of XML code will produce an error? - Line 3 - Miss-
<TextView2 ing = symbol
android:layout_width="wrap_content" after android:lay-
android:layout_height"wrap_content" out_height at-
android:padding="8dp" tribute.
android:text="@string/title" - Line 6 - Missing
android:textSize=18sp /> quotations around
the attribute value
(Choose as many answers as you see fit) 18sp.
- Line 1 - Missing closing tag > after <TextView.
- Line 3 - Missing = symbol after android:layout_height
attribute.
- Line 4 - The android:padding attribute does not exist
for a TextView.
- Line 5 - Use @str/title to refer to a string resource.
- Line 6 - Missing quotations around the attribute value
18sp.

37. Which of the following is true about Gradle? (Choose - Gradle is an au-
as many answers as you see fit) tomated build sys-
tem used by An-
- Gradle is an automated build system used by An- droid Studio to
droid Studio to build your apps. build your apps.
- Gradle handles installing your app on a device. - Gradle handles
- Your app's build.gradle file is written in XML. installing your app
- You can configure Android-specific options for your on a device.
project in your app's build.gradle file. - You can config-
- The gradle configuration for your project cannot ure Android-spe-
change after you initially create the project. cific options for
your project in your
app's build.gradle
file.

38. Which of the following statements about app icons are - mdpi, hdpi, xhdpi,
true? (Choose as many answers as you see fit) xxhdpi, and xxxhd-

11 / 26
Kotlin and Android From Scratch
HÍc trñc tuy¿n t¡i https://quizlet.com/_9fbly5
pi are density qual-
- It is sufficient to provide a single bitmap image of ifiers for resource
your app icon in your project to make it appear high directories to in-
quality on a range of Android devices. dicate that these
- mdpi, hdpi, xhdpi, xxhdpi, and xxxhdpi are densi- are resources to
ty qualifiers for resource directories to indicate that be used on de-
these are resources to be used on devices with a vices with a specif-
specific screen density. ic screen density.
- Adaptive icons are made up of a foreground and - Adaptive icons
background layer, and an OEM mask will be applied are made up of
on top of them. a foreground and
- Vector drawables only work for a certain screen den- background layer,
sity and should not be scaled. and an OEM mask
will be applied on
top of them.

39. Which of the below steps are part of changing the - Modify the
color of your app theme? (Choose as many answers themes.xml (night)
as you see fit) file.
- Set the prima-
- Modify the themes.xml (night) file. ry and secondary
- Set the primary and secondary color theme attribut- color theme attrib-
es of your app theme. utes of your app
- Define the colors used in your app as color resources theme.
in the colors.xml file. - Define the col-
- Set the background color of your app in the activity's ors used in your
layout file. app as color re-
- Set the color attribute on all your UI components. sources in the col-
- Change the name of your theme to your preferred ors.xml file.
color.

40. Why use the Material Components for Android li- - It provides wid-
brary? (Choose as many answers as you see fit) gets that follow the
Material Design
- It provides widgets that follow the Material Design guidelines such as
guidelines such as text fields and switches. text fields and
- It makes your code compile faster. switches.
- It provides default Material themes that you can use - It provides default
directly or extend and then customize. Material themes

12 / 26
Kotlin and Android From Scratch
HÍc trñc tuy¿n t¡i https://quizlet.com/_9fbly5
- It automatically suggests ways for your app to look that you can use
better. directly or extend
- It helps you more quickly build beautiful user expe- and then cus-
riences. tomize.
- It helps you more
quickly build beau-
tiful user experi-
ences.

41. (Fill-in-the-blanks) mutable


Enter one or more words to complete the sentence.
Before running the below code, simpleList should be
initialized as a _______ list.

println(simpleList)
simpleList.add(-5)
simpleList.remove(4)
println(simpleList)

42. Which of the following statements are valid? (Choose - val list = listOf(1,
as many answers as you see fit) 2, 5)
- val oddNum-
- val list = listOf(1, 2, 5) bers = muta-
- val oddNumbers = mutableListOf("1", "9", "15") bleListOf("1", "9",
- val listValues: MutableList<Boolean> "15")
- val fruits = list("apple", "banana", "pear") - val list-
- val words: List<String> = listOf("jump", "run", "skip") Values: Muta-
bleList<Boolean>
- val words:
List<String> =
listOf("jump",
"run", "skip")

43. Why does a RecyclerView need an Adapter? - To create new


ViewHolders and
-To adapt data to display on a specific device type bind data to them
-To create a new ViewGroup
- To adapt data from a data source into JSON
- To create new ViewHolders and bind data to them

13 / 26
Kotlin and Android From Scratch
HÍc trñc tuy¿n t¡i https://quizlet.com/_9fbly5
44. Which of the following are advantages to using Recy- - RecyclerView
clerView (Choose as many answers as you see fit) comes with built-in
layout managers.
- RecyclerView comes with built-in layout managers. - RecyclerView
- RecyclerView lets you use packages to organize your helps save pro-
code. cessing time,
- RecyclerView helps save processing time, which can which can help
help scrolling through a list smoother. scrolling through a
- RecyclerView is designed to be efficient for lists by list smoother.
reusing views that have scrolled off the screen. - RecyclerView is
- RecyclerView automatically incorporates Material designed to be ef-
Design components. ficient for lists by
reusing views that
have scrolled off
the screen.

45. Which of the following is true about packages? - You can use
(Choose as many answers as you see fit) packages to orga-
nize your code.
- You can use packages to organize your code. - In order to use a
- In order to use a class from another package, you class from another
have to explicitly import it in your code. package, you have
- The package name is usually structured from specif- to explicitly import
ic to general. it in your code.
- It is good practice to use packages to group classes - It is good practice
by functionality. to use packages to
group classes by
functionality.

46. What should you do to ensure that the correct type of - Use resource an-
resource ID is passed in to a constructor? notations.

- Use an Adapter to force the type.


- Only use a stringResourceId or imageResourceId.
- Use resource annotations.
- Use a naming convention to pass the ID in the form
R.<type>.
- None of the above

14 / 26
Kotlin and Android From Scratch
HÍc trñc tuy¿n t¡i https://quizlet.com/_9fbly5
47. (Fill-in-the-blanks) num in numbers
Enter one or more words to complete the sentence.

In the below code, should be written in the for loop,


so that the output returned is the list of numbers 1
through 3, with each number printed on a new line.

val numbers = listOf(1, 2, 3)


for (_______) {
println(num)
}

48. Which of the following is false about collections and Lists are un-
higher order functions in Kotlin? ordered, while
maps and sets
- Lists, maps, and sets can all use higher order func- are ordered data
tions. types.
- Lists are unordered, while maps and sets are ordered
data types.
- Like the elements in a set, the keys in a map must be
unique. However, multiple keys can map to the same
value.
- Higher order functions such as map and filter can
take lambda functions as parameters.

49. Given the following code, what is the result of Jeddah


oneWordCities[1]?

val cities = listOf("Jeddah", "Bengaluru", "Shenzhen",


"Abu Dhabi", "Mountain View", "Tripoli", "Bengaluru",
"Lima", "Mandalay", "Tripoli")
val oneWordCities = cities.toSet().toList().filter {
!it.contains(" ") }.sorted()

- Tripoli
- Abu Dhabi
- Jeddah
- Bengaluru

15 / 26
Kotlin and Android From Scratch
HÍc trñc tuy¿n t¡i https://quizlet.com/_9fbly5
50. (Fill-in-the-blanks) extra
Enter one or more words to complete the sentence.

A(n) _________ is a piece of data passed between


activities when launching an intent.

51. If you open an app, and then leave the app using the onCreate(), on-
back button, in which order were the following activity Start(), onStop(),
lifecycle methods called? onDestroy()

- onStart(), onCreate(), onDestroy(), onStop()


- onDestroy(), onStart(), onCreate(), onStop()
- onCreate(), onStart(), onStop(), onDestroy()
- onStart(), onCreate(), onStop(), onDestroy()

52. Which activity lifecycle method would be called if a onPause() be-


dialog appears onscreen, partially obscuring an activ- cause the activi-
ity? ty is still displayed,
but no longer has
- onPause() because the activity is still displayed, but focus.
no longer has focus.
- onStop() because the activity does not need to re-
spond to user input while the dialog is onscreen.
- onResume() because the activity needed to respond
to user input to display the dialog.
- onDestroy() because the activity does not need to
exist so long as it doesn't have focus.

53. Which of the following is true about the lifecycle of a - onStart() can
single activity (Choose as many answers as you see be called multiple
fit) times, while on-
Create() can only
- onStart() can be called multiple times, while onCre- be called once.
ate() can only be called once. - onResume() is
- onStop() can be called multiple times, while on- called when the
Pause() can only be called once. activity gains fo-
- onDestroy() is called when the app enters the back- cus.
ground.
- onResume() is called when the activity gains focus.

16 / 26
Kotlin and Android From Scratch
HÍc trñc tuy¿n t¡i https://quizlet.com/_9fbly5
54. Which of the following is true about the lifecycle of a - onStart() can
single activity (Choose as many answers as you see be called multiple
fit) times, while on-
Create() can only
- onStart() can be called multiple times, while onCre- be called once.
ate() can only be called once. - onResume() is
- onStop() can be called multiple times, while on- called when the
Pause() can only be called once. activity gains fo-
- onDestroy() is called when the app enters the back- cus.
ground.
- onResume() is called when the activity gains focus.

55. Which of the following is false about intents? An implicit intent


always results in
- Both implicit and explicit intents allow your app to the system asking
launch another activity. the user which app
- Explicit intents require you to specify the class of the to open.
activity you want to show.
- Intents are performed using the startActivity()
method.
- An implicit intent always results in the system asking
the user which app to open.

56. An activity contains the following code in onCreate(). The app will crash
What will happen when this code is executed, if the because it at-
intent property is null? tempted to access
the extras property
val message = intent.extras?.getString("mes- on a null object.
sage").toString()

- The app will crash because it attempted to access


the extras property on a null object.
- The app will crash because it attempted to access a
null object.
- The app will not crash because the extras property
is accessed unsafely using '?'
- The app will not crash because the extras property
is accessed safely using '?'

17 / 26
Kotlin and Android From Scratch
HÍc trñc tuy¿n t¡i https://quizlet.com/_9fbly5
57. Which of the following tasks can be performed in - Configuring
onCreate() (Choose as many answers as you see fit) views, such as
setting the layout
- Configuring views, such as setting the layout man- manager of a recy-
ager of a recycler view. cler view.
- Determining the items to be shown in the options - Getting extras
menu. from the intent that
- Setting the onClickListener for items in the options launched the activ-
menu. ity.
- Getting extras from the intent that launched the ac-
tivity.

58. In which method should you handle what happens - onOptionsItemS-


when a button in the app bar is pressed? elected()

- onCreateOptionsMenu()
- openOptionsMenu()
- onOptionsItemSelected()
- onPrepareOptionsMenu()

59. onCreateView() is only called once for a fragment's False


entire lifecycle.

- True
- False

60. Which of the following is a benefit of using frag- All of the above
ments?

- Navigation between fragments allows for more so-


phisticated user interface patterns, such as tab bars.
- Using multiple fragments within an activity allows for
an adaptive layout across multiple screen sizes.
- The same fragments can be reused across multiple
activities.
- All of the above

61. In the fragment lifecycle, which of the following tasks - Binding view ob-
should be performed in onViewCreated()? (Choose as jects to properties
many answers as you see fit) in your fragment
18 / 26
Kotlin and Android From Scratch
HÍc trñc tuy¿n t¡i https://quizlet.com/_9fbly5
- Setting proper-
- Inflating the layout ties of individual
- Binding view objects to properties in your fragment views, such as
- Configuring the options menu a recycler view's
- Setting properties of individual views, such as a adapter
recycler view's adapter

62. In the fragment lifecycle, which of the following tasks Inflating the layout
should be performed in onCreateView()?

- Inflating the layout


- Binding view objects to properties in your fragment
- Configuring the options menu
- Setting properties of individual views, such as a
recycler view's adapter

63. (Fill-in-the-blanks) onSupportNaviga-


Enter one or more words to complete the sentence. teUp()

The ________ method needs to be overridden in the


host activity to ensure your app's fragment-based
navigation responds to the app's "Up" button.

64. Given the code for navigating between two fragments E - Only A and C
in a note-taking app, a list of books and a list of notes, are true.
which of the following is true about the navigation
graph file?

val action = BooksListFragmentsDirections.action-


BooksListToNotesList(bookIndex = index)
holder.view.findNavController().navigate(action)

A - Both the books list and notes list are destinations.


B - The books list fragment has an argument called
bookIndex.
C - There's an action defined on the navigation graph
that goes from the books list to the notes list.

19 / 26
Kotlin and Android From Scratch
HÍc trñc tuy¿n t¡i https://quizlet.com/_9fbly5
D - A, B, and C are true.
E - Only A and C are true.

65. Which of the following are reasons to use a ViewMod- - A ViewModel


el? and its data can
(Choose as many answers as you see fit) survive orientation
changes in an Ac-
- A ViewModel and its data can survive orientation tivity/Fragment.
changes in an Activity/Fragment. - A ViewModel al-
- A ViewModel allows you to separate code that up- lows you to sepa-
dates the UI from code that doesn't need to rely on the rate code that up-
UI or its lifecycle. dates the UI from
- A ViewModel prevents your data from updating the code that doesn't
UI automatically. need to rely on the
UI or its lifecycle.

66. A ViewModel is destroyed after which of the following after onDestroy, if


? it not a configura-
tion change
- always after onStop
- always after onDestroy
- after onDestroy, if it not a configuration change

67. You should execute time-consuming tasks and I/O False


requests in your Activity/Fragment.

- True
- False

68. Why should you initialize and store LiveData in your All of the above
ViewModel instead of a UI Controller?

- Both the ViewModel and LiveData are lifecycle aware.


- To ensure that the LiveData isn't destroyed when the
UI Controller is destroyed.
- To hide or separate implementation details making
your app more flexible.
- All of the above

69. A liveData object


20 / 26
Kotlin and Android From Scratch
HÍc trñc tuy¿n t¡i https://quizlet.com/_9fbly5
observe allows you to do which of the following for
changes?

- a LiveData object
- any mutable object
- any property in a ViewModel
- any property in a ViewModel or LiveData object

70. It's OK for a ViewModel to directly reference a View or False


LifecycleOwner class.

- True
- False

71. You can use the same ViewModel for multiple Activi- True
ties or Fragments to share data.

- True
- False

72. What is the correct way to access the shared view val viewMod-
model using the Kotin property delegate approach? el: OrderViewMod-
el by activityView-
- val viewModel: OrderViewModel by viewModels() Models()
- val viewModel: OrderViewModel by activityViewMod-
els()
- val viewModel: OrderViewModel by sharedViewMod-
els()
- val viewModel: OrderViewModel by fragmentView-
Models()

73. (Fill-in-the-blanks) Transformation


Enter one or more words to complete the sentence.

Use a LiveData _________ to return a different LiveDa-


ta instance based on the value of another instance.

74. How can the apply function in Kotlin be used to con- It can apply a set
figure an object? of assignments to
the object.
21 / 26
Kotlin and Android From Scratch
HÍc trñc tuy¿n t¡i https://quizlet.com/_9fbly5
- It can directly apply the object.
- It can apply a set of assignments to the object.
- It can apply new instances from the object.
- It is not recommended to use apply to configure an
object.

75. Using a data binding layout expression, what's the an-


correct syntax for adding an attribute to the button in droid:onClick="@{()
this layout in order to bind a click listener to it? ->
<Button detailFrag-
android:id="@+id/next_button" ment.next()}"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/next" />

- android:onClick="@{detailFragment.next()}"
- android:onClick="@{(Int) -> detailFragment()}"
- android:click="@{() -> detailFragment.next()}"
- android:onClick="@{() -> detailFragment.next()}"

76. Fill-in-the-blanks Main


(Enter one or more words to complete the sentence)

The ______ thread, sometimes called the UI thread,


is responsible for updating the screen in an Android
app.

77. Which of the following are some of the pitfalls of -Race conditions
directly using threads in your code? -Inconsistent out-
(Choose as many answers as you see fit) put
-Unresponsive UI
-Race conditions
-Inconsistent output
-Unresponsive UI
-Thread is deprecated

78. Which of the following is true about coroutines? A coroutine may or


may not execute.
- Once started, a coroutine cannot be canceled.
- A coroutine always runs on the main thread.
22 / 26
Kotlin and Android From Scratch
HÍc trñc tuy¿n t¡i https://quizlet.com/_9fbly5
- A coroutine may or may not execute.
- Coroutines avoid the need to create new threads, by
running every task on the same thread.

79. (True or False) False

If a function already calls a suspend function, then it


does not need to be marked as a suspend function
itself. True False

80. Which of the following are suspend functions? -The lambda


(Choose as many answers as you see fit) passed into
async()
-async() -The lambda
-The lambda passed into async() passed into run-
-runBlocking() Blocking()
-The lambda passed into runBlocking()

81. Which of the following are false about async() and Both functions re-
runBlocking()? turn a Deferred

- Both functions take a CoroutineScope (a suspend


function) as a parameter
- Both functions return a Deferred
- You'll typically not use runBlocking in Android app
code
- When using async, you need to use await() to access
the returned value

82. (True or False) False

In most apps, you would create coroutines using the


global scope.

83. What is responsible for determining which thread is Dispatcher


used behind the scenes by a coroutine?

- CoroutineScope
- Dispatcher

23 / 26
Kotlin and Android From Scratch
HÍc trñc tuy¿n t¡i https://quizlet.com/_9fbly5
- Job
- GlobalScope

84. Fill-in-the-blanks Deffered


(Enter one or more words to complete the sentence)

A ______ is similar to a promise or future in other


languages and serves as a placeholder for a return
value.

85. (True or False) True

A Job is a cancelable unit of work performed by a


coroutine.

86. Which of the following are required to load and display -The URL of the
an image with coil? image
(Choose as many answers as you see fit) -An ImageView

-A placeholder image
-An error image
-The URL of the image
-An ImageView

87. Match the element of HTTP requests and responses Status Message ->
to the correct term. OK
(Each answer only matches one item) Status Code ->
200
Requests: Status Messages, Status Code, HTTP Verb, HTTP Verb ->
Content-Type POST
Responses: POST, 200, OK, application/json Content-Type ->
application/json

88. Which of the following are characteristics of a REST- - Stateless


ful service? - Client-server-ar-
(Choose as many answers as you see fit) chitecture
- Resources ex-
- Stateless posed as URIs
- JSON responses

24 / 26
Kotlin and Android From Scratch
HÍc trñc tuy¿n t¡i https://quizlet.com/_9fbly5
- Client-server-architecture
- Resources exposed as URIs

89. Which of the following are needed to make a network - Add the
request with Retrofit? android.permis-
(Choose as many answers as you see fit) sion.INTERNET
permission to the
- Add the android.permission.INTERNET permission manifest
to the manifest - Include Retrofit
- Include Retrofit Gradle dependency Gradle dependen-
- Supply a base URL to the Retrofit.Builder object, cy
- Add coil library as a Gradle dependency. - Supply a base
URL to the Retro-
fit.Builder object,

90. Why do you declare DataProviderManager with the - To make this ob-
object keyword? ject a singleton
(Choose as many answers as you see fit) - You only need
one instance of the
- To make this object a singleton object.
- A shared object provides a convenient way to store
state
- You only need one instance of the object.
- DataProviderManager is an object and not a class.

91. Which of the following are true about grid layouts? - By default, a grid
(Choose as many answers as you see fit) layout scrolls verti-
cally
- By default, a grid layout scrolls vertically - A grid layout is
- A grid layout is ideal for lists that can be represented ideal for lists that
as icons or images can be represent-
- A span is equal to the width of one row ed as icons or im-
- You can reference the object by its type name, Dat- ages
aProviderManager. - You can ref-
erence the ob-
ject by its type
name, DataProvi-
derManager.

92. Path
25 / 26
Kotlin and Android From Scratch
HÍc trñc tuy¿n t¡i https://quizlet.com/_9fbly5
In the URL https://google.com/search?q=android,
'/search' is called the _______

- Host
- Path
- Query
- Parameters

93. Which of the following are true about binding - Binding adapters
adapters? allow you to imple-
(Choose as many answers as you see fit) ment custom log-
ic for how layout
- A binding adapter only provides an alternate way to attributes are as-
set a hardcoded value. signed.
- Binding adapters allow you to implement custom - @Bindin-
logic for how layout attributes are assigned. gAdapter methods
- The @BindingAdapter annotation requires the view process custom
as an argument values that are
- @BindingAdapter methods process custom values provided to XML
that are provided to XML attributes. attributes.

94. (True or False) True

Retrofit creates the code required to make network


requests based on a web service

95. The Moshi library requires the following to success- - A data class de-
fully process JSON in Kotlin. scribing the struc-
(Choose as many answers as you see fit) ture of the JSON
object.
- A data class describing the structure of the JSON -
object. KotlinJsonAdapter-
- KotlinJsonAdapterFactory() added to the Factory() added to
Moshi.Builder object. the Moshi.Builder
- A MoshiConverterFactory added to the Retro- object.
fit.Builder object. - A MoshiConvert-
- All properties in the data class marked with the erFactory added to
@JSON annotation. the Retrofit.Builder
object.

26 / 26

You might also like