Associate-Android-Developer Associate Android Developer

Loading demo links...

Showing 7–9 of 10 questions

Question 7 (KOTLIN only)

For example, we have a BufferedReader reader, associated with the json file through InputStreamReader. To get a file data we can do this:

Select an option, then click Submit answer.

  • var line: String? try {
    while (reader.readLine().also { line = it } != null) { builder.append(line)
    }
    val json = JSONObject(builder.toString()) return json
    } catch (exception: IOException) { exception.printStackTrace() } catch (exception: JSONException) { exception.printStackTrace()
    }

  • var line: JSONObject ? try {
    while (reader.readJSONObject ().also { line = it } != null) { builder.append(line)
    }
    val json = JSONObject(builder.toString()) return json
    } catch (exception: IOException) { exception.printStackTrace() } catch (exception: JSONException) { exception.printStackTrace()
    }

  • var line: String?
    try {
    while (reader.readLine().also { line = it } != null) { builder.append(line)
    }
    val json = JSONObject(builder.toString()) return json
    } catch (exception: RuntimeException) { exception.printStackTrace()
    } catch (exception: ArrayIndexOutOfBoundsException) { exception.printStackTrace()
    }

Question 8 (KOTLIN only)

An example. In our ViewModelFactory (that implements ViewModelProvider.Factory) we have an instance of our Repository, named mRepository. Our ViewModel has such constructor:

class MyViewModel(private val mRepository: MyRepository) : ViewModel() ...

Next, in our ViewModelFactory create ViewModel method (overriden) looks like this: override fun create(modelClass: Class): T { return try {

//MISSED RETURN VALUE HERE”

} catch (e: InstantiationException) {

throw RuntimeException("Cannot create an instance of $modelClass", e)

} catch (e: IllegalAccessException) {

throw RuntimeException("Cannot create an instance of $modelClass", e)

} catch (e: NoSuchMethodException) {

throw RuntimeException("Cannot create an instance of $modelClass", e)

} catch (e: InvocationTargetException) {

throw RuntimeException("Cannot create an instance of $modelClass", e)

} }

What should we write instead of “//MISSED RETURN VALUE HERE”?

Select an option, then click Submit answer.

  • modelClass.getConstructor()
    .newInstance(mRepository)

  • modelClass.getConstructor(MyRepository::class.java) .newInstance()

  • modelClass.getConstructor(MyRepository::class.java)
    .newInstance(mRepository)

Question 9 (KOTLIN only)

By default, the notification's text content is truncated to fit one line. If you want your notification to be longer, for example, to create a larger text area, you can do it in this way:

Select an option, then click Submit answer.

  • var builder = NotificationCompat.Builder(this, CHANNEL_ID)
    .setContentText("Much longer text that cannot fit one line...")
    .setStyle(NotificationCompat.BigTextStyle()
    .bigText("Much longer text that cannot fit one line...")) ...

  • var builder = NotificationCompat.Builder(this, CHANNEL_ID)
    .setContentText("Much longer text that cannot fit one line...")
    .setLongText("Much longer text that cannot fit one line..."))
    ...

  • var builder = NotificationCompat.Builder(this, CHANNEL_ID)
    .setContentText("Much longer text that cannot fit one line...")
    .setTheme(android.R.style.Theme_LongText); ...