Kotlin-and-Android-From-Scratch
Kotlin-and-Android-From-Scratch
- fun
- func
- function
- newFunction
- main
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!")
}
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)
}
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.
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
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
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
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.
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?
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?
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.
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
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>
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.
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")
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.
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.
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.
- 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.
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()
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.
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()
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.
- onCreateOptionsMenu()
- openOptionsMenu()
- onOptionsItemSelected()
- onPrepareOptionsMenu()
- True
- False
60. Which of the following is a benefit of using frag- All of the above
ments?
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()?
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?
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.
- True
- False
68. Why should you initialize and store LiveData in your All of the above
ViewModel instead of a UI Controller?
- a LiveData object
- any mutable object
- any property in a ViewModel
- any property in a ViewModel or LiveData object
- 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()
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.
- android:onClick="@{detailFragment.next()}"
- android:onClick="@{(Int) -> detailFragment()}"
- android:click="@{() -> detailFragment.next()}"
- android:onClick="@{() -> detailFragment.next()}"
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
81. Which of the following are false about async() and Both functions re-
runBlocking()? turn a Deferred
- CoroutineScope
- Dispatcher
23 / 26
Kotlin and Android From Scratch
HÍc trñc tuy¿n t¡i https://quizlet.com/_9fbly5
- Job
- GlobalScope
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
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.
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