-
Notifications
You must be signed in to change notification settings - Fork 0
Android
- Errors
- Http Requests
- Exercises
Add explicitly the library with the old version but with a new version number:
com.android.support:customtabs:26.1.0
-> implementation 'com.android.support:customtabs:27.0.2'
Take the library from the second item, and implement it with the version number from the first.
1.
class ActivityA : Activity() {
private var counter1 : Int = 0
private var counter2 : Int = 0
private var counter3 : Int = 0
override fun onCreate(savedInstanceState: Bundle?) {
super .onCreate(savedInstanceState)
setContentView(R.layout. activity_a )
button.setOnClickListener { startActivity(Intent( this , ActivityB:: class . java )) }
if (savedInstanceState != null )
counter2 = savedInstanceState .getInt( "counter2" )
Log.v( "ActivityA" , "counter1 = ${ ++ counter1 } " ) // (1)
Log.v( "ActivityA" , "counter2 = ${ ++ counter2 } " ) // (2)
}
override fun onSaveInstanceState(outState: Bundle?) {
super .onSaveInstanceState(outState)
outState?.putInt( "counter2" , counter2 )
}
override fun onStart() {
super .onStart()
Log.v( "ActivityA" , "counter3 = ${ ++ counter3 } " ) // (3)
}
}
1.1 For the sequence of events:
- ActivityA is initialized for the first time
- Device screen changes orientation
The last two messages written in the log on lines //1 and //2 contain:
1. counter1 = 1 e counter2 = 2---------------
2. counter1 = 1 e counter2 = 1
3. counter1 = 2 e counter2 = 1
4. None of the above
Answer
:
1.2 For the sequence of events:
- ActivityA is initialized for the first time
- Button is pressed
- User travels to the initial activity (presses back button)
The sequence of messages written in the log contain:
1. counter1 = 1; counter2 = 1; counter3 = 1; counter3 = 1
2. counter1 = 1; counter2 = 1; counter3 = 1; counter1 = 2; counter2 = 2; counter3 = 2
3. counter1 = 1; counter2 = 1; counter3 = 1; counter3 = 2--------------------------
4. None of the above
Answer
:
1.3 For the sequence of events:
- ActivityA is initialized for the first time
- Button is pressed
- Device screen changes orientation
- User travels to the initial activity (presses back button)
The sequence of messages written in the log contain:
1. counter1 = 1; counter2 = 1; counter3 = 1; counter3 = 1
2. counter1 = 1; counter2 = 1; counter3 = 1; counter1 = 1; counter2 = 2; counter3 = 1 ------------------------
3. counter1 = 1; counter2 = 1; counter3 = 1; counter3 = 2
4. Nenhuma das anteriores
Answer
:
2.
The Room
framework contains Database, Data Access Objects (DAO) and Entities within its programming model.
1. DAOs are classes defined by the programmer and represent the data to store in the database.
2. DAOs are classes defined by the programmer and contain code implementation relative to database access.
3. DAOs are interfaces defined by the programmer that caracterize the database access operations and have their implementation generated in building time.------------
4. None of the above.
Answer
:
3.
Considering the class android.os.AsyncTask
, the implementation of the class guarantees that:
1. The methods `doInBackground` and `onPostExecute` are executed in the thread where the instance was created.
2. The method `doInBackground` is executed in a thread pool reserved for that effect and the method `onPostExecute` is executed in the UI thread.-----------
3. The methods `doInBackground` and `onPostExecute` are executed in a thread pool reserved for that effect.
4. None of the above.
Answer
:
4.
A work (WorkRequest) scheduled to be executed by the WorkManager
:
1. Is initialized only when the application is running with a visible activity.
2. Is initialized only if the application is running, even if no activity is visible at the time.
3. Is initialized even if the application is not currently running.-------
4. None of the above.
Answer
:
5.
The invocation on the UI thread of the method public fun <T> add( request: Request<T>): Request<T>
from an instance of RequestQueue
from the Volley
library:
1. Is not allowed because it makes a network access.
2. Can be made, even if the request response time is long.-----------------
3. Can block the user interface, if the request response time is long.
4. Can only be made if the user accepts the permission ALLOW_REQUESTS_IN_UI_THREAD.
Answer
:
6.
Considering an instance of RecyclerView.Adapter
, the number of calls to onBindViewHolder is
:
1. Greater or equal to the number of calls to `onCreateViewHolder`.--------------------
2. Equal to the number of calls to `onCreateViewHolder`.
3. Less or equal to the number of calls to `onCreateViewHolder`.
4. Independent to the number of calls to `onCreateViewHolder`.
Answer
:
7.
Consider the following sequence of events:
* An instance of MutableLiveData<Int>
is created and initialized with the value 11.
* An observer is registered on that instance of MutableLiveData<Int>
.
* The value of the instance is changed to 12.
* The value of the instance is changed to 12.
How many times is the code of the registered observer executed?
1. Once, with the value 12.
2. Twice, with the values 11 and 12.
3. Twice, with the values 12 and 13.
3. Three times, with the values 11, 12 and 13. -----------------
Answer
:
8.
One of the utilities of the manifest file in an android application is:
1. Define the language in which the application is presented.
2. Define the dimension of each activity.
3. Define if the application uses Java or Kotlin.
4. None of the above. ------------
Answer
:
9.
Given an application composed by ActivityA
shown below, and any other acvitity called AcvitityB
:
class ViewModelA( var onCreateCounter : Int = 0 , var onStartCounter : Int = 0 ) : ViewModel()
class ActivityA : AppCompatActivity() {
private lateinit var model : ViewModelA
override fun onCreate(savedInstanceState: Bundle?) {
super .onCreate(savedInstanceState)
setContentView(R.layout. activity_a )
button.setOnClickListener { startActivity(Intent( this , ActivityB:: class . java )) } // (4)
model = ViewModelProviders.of( this ).get(ViewModelA:: class . java )
Log.v( "ActivityATag" , "onCreateCounter = ${ ++ model . onCreateCounter } " ) // (1)
Log.v( "ActivityATag" , "viewModel hash = ${ model .hashCode() } ; " // (3)
+ "activity hash = ${ hashCode() } " ) // (3)
}
override fun onStart() {
super .onStart()
Log.v( "ActivityATag" , "onStartCounter = ${ ++ model . onStartCounter } " ) // (2)
}
}
9.1
For the sequence of events:
* ActivityA is initialized for the first time.
* Device screen changes orientation.
The messages written in the log on lines //1 and //2 contain:
1. onCreate = 1 e onStart = 2.
2. onCreate = 1 e onStart = 1.
3. onCreate = 2 e onStart = 1.
4. Nenhuma das anteriores. -----------
Answer
:
9.2
In the line marked with // (4) an Intent
is instantiated that is said to be:
1. Explicit because the recipient is known at compile time.----------
2. Explicit because it does not contain extras.
3. Implicit because the recipient is only known at runtime.
4. None of the above.
Answer
:
9.3
For the sequence of events:
* ActivityA is initialized for the first time.
* Device screen changes orientation.
* User selects another user task (process which holds the application that contains ActivityA is terminated).
* User selects the task that contains ActivityA again.
The messages written in the log on lines //1 and //2 contain:
1. onCreate = 1; onStart = 1; onCreate = 2; onStart = 2; onStart = 3
2. onCreate = 1; onStart = 1; onCreate = 2; onStart = 2; onCreate = 1; onStart = 1----------------
3. onCreate = 1; onStart = 1; onCreate = 2; onStart = 2; onStart = 1
4. None of the above because the system cannot kill the process.
Answer
:
9.4
For the sequence of events:
* ActivityA is initialized for the first time.
* Device screen changes orientation.
* User selects another user task (process which holds the application that contains ActivityA is terminated).
* User selects the task that contains ActivityA again.
The messages written in the log on line //3 contain:
1. Have different values in `viewModel hash` and equal values in `activity hash`.
2. Have equal values in `viewModel hash` and in `activity hash`.
1. Have equal values in `viewModel hash` and different values in `activity hash`.-----------------
1. Have different values in `viewModel hash` and in `activity hash`.
Note: admit that the hash value does not change during the lifetime of the object and has different values for different objects.
Answer
:
10.
According to Android Jetpack's guide to architecture:
1. Each activity delegates action processing in the `ViewModel`, which in turn checks the UI elements of that activity when necessary.
2. It is the `ViewModel` job to determine if it should get data from a remote api or the local database.
3. It is not admissible that the `Repository` accesses the `ViewModel` instances to consult or modify data, because that violates the dependency direction defined in the architecture.-----------------
4. It is consideres bad practice for objects that contain data obtained from the network and state of the network operation itself to be published by the `ViewModel`.
Answer
:
11.
The framwork SharedPreferences supplies an API for persistene storage of user preferences in the system files. The API includes the interface SharedPreferences.Editor
that contains methods to write and remove values. It also contains the method fun commit() : Boolean
and its asynchronous counterpart fun apply() : Unit
.
1. The method `apply` makes changes to the memory only, being necessary to invoke `commit` after.
2. Both methods perform memory updates once in a persisten fashion.------------
3. It is not allowed to call any of the methods from the UI thread.
4. None of the above.
Answer
: