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:
Avar 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...")) ...
Bvar builder = NotificationCompat.Builder(this, CHANNEL_ID) .setContentText("Much longer text that cannot fit one line...") .setLongText("Much longer text that cannot fit one line...")) ...
Cvar builder = NotificationCompat.Builder(this, CHANNEL_ID) .setContentText("Much longer text that cannot fit one line...") .setTheme(android.R.style.Theme_LongText); ...
Select correct demonstration of WorkRequest cancellation.
The easiest way of adding menu items (to specify the options menu for an activity) is inflating an XML file into the Menu via MenuInflater. With menu_main.xml we can do it in this way:
Coverride fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.menu.menu_main) }
Android Tests. You can use the childSelector() method to nest multiple UiSelector instances. For example, the following code example shows how your test might specify a search to find the first ListView in the currently displayed UI, then search within that ListView to find a UI element with the text property Apps. What is the correct sample?
The following code snippet shows an example of an Espresso test:
A@Rule fun greeterSaysHello() { onView(withId(R.id.name_field)).do(typeText("Steve")) onView(withId(R.id.greet_button)).do(click()) onView(withText("Hello Steve!")).check(matches(isDisplayed())) }
B@Test fun greeterSaysHello() { onView(withId(R.id.name_field)).perform(typeText("Steve")) onView(withId(R.id.greet_button)).perform(click()) onView(withText("Hello Steve!")).check(matches(isDisplayed())) }
C@Test fun greeterSaysHello() { onView(withId(R.id.name_field)).do(typeText("Steve")) onView(withId(R.id.greet_button)).do(click()) onView(withText("Hello Steve!")).compare(matches(isDisplayed())) }
As an example. In an Activity we have our TimerViewModel object (extended ViewModel), named mTimerViewModel. mTimerViewModel.timer method returns a LiveData<Long> value. What can be a correct way to set an observer to change UI in case if data was changed?
AmTimerViewModel!!.timer.value.toString().observe (Observer { aLong -> callAnyChangeUIMethodHere(aLong!!) })
BmTimerViewModel!!.timer.observe (this, Observer { aLong -> callAnyChangeUIMethodHere(aLong!!) })
CmTimerViewModel.observe (Observer { aLong -> callAnyChangeUIMethodHere(aLong!!) })
LiveData.postValue() and LiveData.setValue() methods have some differences. So if you have a following code executed in the main thread: liveData.postValue("a"); liveData.setValue("b");
What will be the correct statement?
AThe value "b" would be set at first and later the main thread would override it with the value "a".
BThe value "a" would be set at first and later the main thread would override it with the value "b".
CThe value "b" would be set at first and would not be overridden with the value "a".
DThe value "a" would be set at first and would not be overridden with the value "b".
For example, our preferences.xml file was added by addPreferencesFromResource(R.xml.preferences). Our preferences.xml file contains such item:
<SwitchPreference
android:id="@+id/notification"
android:key="@string/pref_notification_key"
android:title="@string/pref_notification_title"
android:summary="@string/pref_notification_summary"
android:defaultValue="@bool/pref_notification_default_value"
app:iconSpaceReserved="false"/>
In our Fragment, we can dynamically get current notification preference value in this way:
For example, our preferences.xml file was added by addPreferencesFromResource(R.xml.preferences). Our preferences.xml file contains such item:
<ListPreference
android:id="@+id/order_by"
android:key="@string/pref_sort_key"
android:title="@string/pref_sort_title"
android:summary="@string/pref_sort_summary"
android:dialogTitle="@string/pref_sort_dialog_title"
android:entries="@array/sort_oder"
android:entryValues="@array/sort_oder_value"
android:defaultValue="@string/pref_default_sort_value"
app:iconSpaceReserved="false" />
In our Fragment, we can dynamically get current notification preference value in this way:
For example, we have a file in our raw folder app/src/main/res/raw/sample_teas.json. To get an InputStream for reading it, from out Context context, we can do this:
For example, we have a BufferedReader reader, associated with the json file through InputStreamReader. To get a file data we can do this:
Avar 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() }
Bvar 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() }
Cvar 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() }
For example, we have a file in our assets folder app/src/main/assets/sample_teas.json. To get an InputStream for reading it, from out Context context, we can try do this:
To automate UI tests with Android Studio, you implement your test code in a separate Android test folder. Folder could be named:
Aapp/androidTest/java
Bapp/src/androidTest/java
Capp/java/androidTest
Once your test has obtained a UiObject object, you can call the methods in the UiObject class to perform user interactions on the UI component represented by that object. You can specify such actions as: (Choose four.)
Aclick() : Clicks the center of the visible bounds of the UI element.
Btouch() : Touch the center of the visible bounds of the UI element.
CdragTo() : Drags this object to arbitrary coordinates.
DmoveTo() : Move this object to arbitrary coordinates.
EsetText() : Sets the text in an editable field, after clearing the field's content. Conversely, the clearTextField() method clears the existing text in an editable field.
FswipeUp() : Performs the swipe up action on the UiObject. Similarly, the swipeDown(), swipeLeft(), and swipeRight() methods perform corresponding actions.