You might have instances in your capsule where you need to poll your content provider with updated information, for example if you need to update the contents displayed to your user about some information. In these cases, you can use the refresh
reference key in a result-view
, input-view
, or confirmation-view
file to accomplish this. Refreshes are especially useful when updating a user on the current status of an Activity, such as the location of a user's last order. However, you do not need to have an Activity to use a refresh.
For example, you might want to create a ride-sharing capsule. In order for users to get live updates of when their ride will arrive, you can update the views with refresh
in your view file, like in this example from the Refreshing Content sample capsule:
refresh {
if (this.countdown != 0) {
spec {
delay-seconds (5)
with-request {
intent {
goal: CheckRideShareStatus
value {
$expr (this)
}
}
}
}
}
}
Bixby will refresh if and only if the user is still on Bixby. Once they leave Bixby, the refresh will no longer happen.
Refreshing your content affects both your View and the text-to-speech (TTS) that is spoken aloud by Bixby. The Simulator emulates this behavior for you, although the device might react faster. Try on-device testing to be sure of how refreshing will behave.
You can find another example of using refresh
in the reference page. You can also check out the Refresh Sample Capsule.
To further expand on the ride-sharing example, the refresh
key is declared in a result-view
file:
result-view {
match {
Activity (this){
min(Required) max (One)
}
}
message {
if (this.countdown != 0) {
template ("Your ride will arrive in #{value(this.countdown)} seconds.")
}
else {
template ("I hope you are enjoying your ride")
}
}
refresh {
if (this.countdown != 0) {
spec {
delay-seconds (5)
with-request {
intent {
goal: CheckRideShareStatus
value {
$expr (this)
}
}
}
}
}
}
render {
layout {
macro (activity-map-macro) {
param (activity) {
expression (this)
}
}
}
}
}
This Activity.view.bxb
file displays to users the details of the ride-share status. The delay-seconds
key handles how often the view is refreshed, which is checked using a conditional for the countdown
property. The with-request
key has an intent
to execute during each refresh interval. It calls the CheckRideShareStatus
:
action (CheckRideShareStatus) {
type (Calculation)
collect {
input (activity) {
type (Activity)
min (Required)
default-init {
intent {
goal: Activity
value: Countdown (20)
}
}
}
}
output (Activity)
}
Once the ride is over (in this case, when the countdown reaches zero), the refresh will stop.
If you have a transactional capsule and you need to access information from a content provider, in order to get a refreshed state of the action, that action needs to be of the type RefreshActivity
. To learn more about how to use Activity Cards to update users during Refresh Activity, see Updates with Activity Cards.