Selam,
İlk codelab’le ilgili yazıya buradan ( Android fundamentals 01.1: Android Studio and Hello World ) erişebilirsiniz. Devam edelim.
Codelab’leri biraz inceledikten sonra belki bir giriş yazısı anlamlıydı ama devamı için şimdilik sadece kod örneklerinin Kotlin versiyonunun yeterli olacağı kanısındayım. Codelableri yaparken yazıma denk geldiyseniz ve sorunuz varsa, bloga yorum olarak gönderebilirsiniz. Aşağıdaki projeler Unit 1 için örnekleri içermektedir.
İyi çalışmalar.
Projeler:
Android fundamentals 01.2 Part A: Your first interactive UI
Android fundamentals 01.2 Part B: The layout editor
Android fundamentals 01.3: Text and scrolling views
Android fundamentals 01.4: Learn to help yourself
Android fundamentals 02.1: Activities and intents
Android fundamentals 02.2: Activity lifecycle and state
Android fundamentals 02.3: Implicit intents
Android fundamentals 03.1: The debugger
- Varolan uygulama üzerinden debugging konuşulduğu için tekrar kodlamadım. Soru cevap kısmını aşağıda bulabilirsiniz.
Android fundamentals 03.2: Unit tests
- Varolan uygulama üzerinden unit test konuşulduğu için tekrar kodlamadım. Soru cevap kısmını aşağıda bulabilirsiniz.
Android fundamentals 03.3: Support libraries
Answer the questions:
Android fundamentals 01.2 Part B: The layout editor
Question 1
Which two layout constraint attributes on the Zero Button
position it vertically equal distance between the other two Button
elements? (Pick 2 answers.)
app:layout_constraintBottom_toTopOf="@+id/button_count"
android:layout_marginBottom="8dp"
android:layout_marginStart="16dp"
app:layout_constraintTop_toBottomOf="@+id/button_toast"
android:layout_marginTop="8dp"
Question 2
Which layout constraint attribute on the Zero Button
positions it horizontally in alignment with the other two Button
elements?
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintBottom_toTopOf="@+id/button_count"
android:layout_marginBottom="8dp"
app:layout_constraintTop_toBottomOf="@+id/button_toast"
Question 3
What is the correct signature for a method used with the android:onClick
XML attribute?
public void callMethod()
public void callMethod(View view)
private void callMethod(View view)
public boolean callMethod(View view)
Question 4
The click handler for the Count Button
starts with the following method signature:
public void countUp(View view)
Which of the following techniques is more efficient to use within this handler to change the Button
element’s background color? Choose one:
- Use
findViewById
to find the CountButton
. Assign the result to aView
variable, and then usesetBackgroundColor()
. - Use the
view
parameter that is passed to the click handler withsetBackgroundColor()
:view.setBackgroundColor()
Android fundamentals 01.3: Text and scrolling views
Question 1
How many views can you use within a ScrollView
? Choose one:
- One view only
- One view or one view group
- As many as you need
Question 2
Which XML attribute do you use in a LinearLayout
to show views side by side? Choose one:
android:orientation="horizontal"
android:orientation="vertical"
android:layout_width="wrap_content"
Question 3
Which XML attribute do you use to define the width of the LinearLayout
inside the scrolling view? Choose one:
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_width="200dp"
01.4: Learn to help yourself
Question 1
Within an Android Studio project, what menu command can you use to open the list of sample apps? Choose one:
- File > Open
- File > New > Import Sample
- File > New > Import Module
- File > New > Import Project
Question 2
Which buttons does the Basic Activity template provide as part of the UI? Choose two:
- Navigation buttons
- Options menu overflow button
- Floating action button
Button
class button with the text “Button”
Question 3
Which source of documentation is the official documentation for Android developers? Choose one:
- stackoverflow.com
- officialandroid.blogspot.com
- developer.android.com
- github.com
Android fundamentals 01.4: Learn to help yourself
Question 1
What changes are made when you add a second Activity
to your app by choosing File > New > Activity and an Activity
template? Choose one:
- The second
Activity
is added as a Java class. You still need to add the XML layout file. - The second
Activity
XML layout file is created and a Java class added. You still need to define the class signature. - The second
Activity
is added as a Java class, the XML layout file is created, and theAndroidManifest.xml
file is changed to declare a secondActivity
. - The second
Activity
XML layout file is created, and theAndroidManifest.xml
file is changed to declare a secondActivity
.
Question 2
What happens if you remove the android:parentActivityName
and the <meta-data>
elements from the second Activity
declaration in the AndroidManifest.xml
file? Choose one:
- The second
Activity
no longer appears when you try to start it with an explicitIntent
. - The second
Activity
XML layout file is deleted. - The Back button no longer works in the second
Activity
to send the user back to the mainActivity
. - The Up button in the app bar no longer appears in the second
Activity
to send the user back to the parentActivity
.
Question 3
Which constructor method do you use to create a new explicit Intent
? Choose one:
new Intent()
new Intent(Context context, Class<?> class)
new Intent(String action, Uri uri)
new Intent(String action)
Question 4
In the HelloToast app homework, how do you add the current value of the count to the Intent
? Choose one:
- As the
Intent
data - As the
Intent
TEXT_REQUEST
- As an
Intent
action - As an
Intent
extra
Question 5
In the HelloToast app homework, how do you display the current count in the second “Hello” Activity
? Choose one:
- Get the
Intent
that theActivity
was launched with. - Get the current count value out of the
Intent
. - Update the
TextView
for the count. - All of the above.
Android fundamentals 02.2: Activity lifecycle and state
Question 1
If you run the homework app before implementing onSaveInstanceState()
, what happens if you rotate the device? Choose one:
- The
EditText
no longer contains the text you entered, but the counter is preserved. - The counter is reset to 0, and the
EditText
no longer contains the text you entered. - The counter is reset to 0, but the contents of the
EditText
is preserved. - The counter and the contents of the
EditText
are preserved.
Question 2
What Activity
lifecycle methods are called when a device-configuration change (such as rotation) occurs? Choose one:
- Android immediately shuts down your
Activity
by callingonStop()
. Your code must restart theActivity
. - Android shuts down your
Activity
by callingonPause()
,onStop()
, andonDestroy()
. Your code must restart theActivity
. - Android shuts down your
Activity
by callingonPause()
,onStop()
, andonDestroy()
, and then starts it over again, callingonCreate()
,onStart()
, andonResume()
. - Android immediately calls
onResume()
.
Question 3
When in the Activity
lifecycle is onSaveInstanceState()
called? Choose one:
onSaveInstanceState()
is called before theonStop()
method.onSaveInstanceState()
is called before theonResume()
method.onSaveInstanceState()
is called before theonCreate()
method.onSaveInstanceState()
is called before theonDestroy()
method.
Question 4
Which Activity
lifecycle methods are best to use for saving data before the Activity
is finished or destroyed? Choose one:
onPause()
oronStop()
onResume()
oronCreate()
onDestroy()
onStart()
oronRestart()
Android fundamentals 02.3: Implicit intents
Question 1
Which constructor method do you use to create an implicit Intent
to launch a camera app?
new Intent()
new Intent(Context context, Class<?> class)
new Intent(String action, Uri uri)
new Intent(String action)
Question 2
When you create an implicit Intent
object, which of the following is true?
- Don’t specify the specific
Activity
or other component to launch. - Add an
Intent
action orIntent
categories (or both). - Resolve the
Intent
with the system before callingstartActivity()
orstartActivityforResult()
. - All of the above.
Question 3
Which Intent
action do you use to take a picture with a camera app?
Intent takePicture = new Intent(Intent.ACTION_VIEW);
Intent takePicture = new Intent(Intent.ACTION_MAIN);
Intent takePicture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
Intent takePicture = new Intent(Intent.ACTION_GET_CONTENT);
Android fundamentals 03.1: The debugger
Question 1
Run the SimpleCalc app without the debugger. Leave one or both of the EditText
elements empty, and try any calculation. Why did the error occur?
java.lang.NumberFormatException: empty String
W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED
- The app may be doing too much work on its main thread.
- The code cache capacity was increased to 128KB.
Question 2
Which function do you perform in the Debug pane in order to execute the current line where the breakpoint is, and then stop at the next line in the code? Choose one:
- Step Into
- Step Over
- Step Out
- Resume
Question 3
Which function do you perform in the Debug pane in order to jump to the execution of a method call from the current line where the breakpoint is? Choose one:
- Step Into
- Step Over
- Step Out
- Resume
Android fundamentals 03.2: Unit tests
Question 1
Which statement best describes a local unit test? Choose one:
- Tests that run on an Android-powered device or emulator and have access to the Android framework.
- Tests that enable you to write automated UI test methods.
- Tests that are compiled and run entirely on your local machine with the Java Virtual Machine (JVM).
Question 2
Source sets are collections of related code. In which source set are you likely to find unit tests? Choose one:
app/res
com.example.android.SimpleCalcTest
com.example.android.SimpleCalcTest (test)
com.example.android.SimpleCalcTest (androidTest)
Question 3
Which annotation is used to mark a method as an actual test? Choose one:
@RunWith(JUnit4.class)
@SmallTest
@Before
@Test
Android fundamentals 03.3: Support libraries
Question 1
Which class appears when you first Step Into the ContextCompat.getColor()
method? Choose one:
MainActivity
ContextCompat
AppCompatActivity
Context
Question 2
In the class that appears, which statement is executed if the build version is API version 23 or newer? Choose one:
return context.getColor(id);
return context.getResources().getColor(id);
throw new IllegalArgumentException("permission is null");
return mResources == null ? super.getResources() : mResources;
Question 3
If you change the ContextCompat.getColor()
method back to the getColor()
method, what will happen when you run the app? Choose one:
- If your
minSdkVersion
is 15, the wordgetColor
is underlined in red in the code editor. Hover your pointer over it, and Android Studio reports “Call requires API 23 (current min is 15)”. - The app will run without error on emulators and devices using API 23 or newer.
- The app will crash when the user taps Change Color if the emulator or device is using API 17.
- All of the above.
References:
- https://codelabs.developers.google.com/codelabs/android-training-layout-editor-part-a/index.html?index=..%2F..android-training#0
- https://google-developer-training.github.io/android-developer-fundamentals-course-concepts-v2/unit-1-get-started/lesson-1-build-your-first-app/1-2-c-layouts-and-resources-for-the-ui/1-2-c-layouts-and-resources-for-the-ui.html
- https://docs.google.com/presentation/d/10ARO1cnG0E34igbyPZfyV2rr_skdHtHKMsnbvGoYUKY/edit