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.
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
.
refresh {
if (!exists(this.receipt)) {
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.
You can find an example of using refresh
in the reference page.
To further expand on the ride-sharing capsule, the refresh
key is declared in a result-view
file:
//Activity.view.bxb
result-view {
match {
Activity (this)
}
refresh {
if (!exists(this.receipt)) {
spec {
delay-seconds (5)
with-request {
intent {
goal: CheckRideShareStatus
value {$expr(this)}
}
}
}
}
}
conversation-drivers {
if ("this.status == 'Requested' || this.status == 'Confirmed'") {
conversation-driver {
template ("Cancel my Uber ride")
}
}
}
render {
layout-match (this) {
mode (Details)
}
}
}
The capsule uses a transactional workflow. This Activity.view.bxb
file displays to users the details of the ride-share status. After showing the initial results, if the transaction has moved to the activity state, then the view will refresh. Once the ride is over, which is checked with the condition
by the existence of a receipt
, then the refresh will stop. Otherwise, if the condition
is met, then every 5 seconds, the view is updated. The delay
handles how often the view is refreshed. The on-refresh
has an intent
to execute during each refresh interval. It calls the CheckRideShareStatus
, which is of the RefreshActivity
type.
action (CheckRideShareStatus) {
type (RefreshActivity)
collect {
input(activity){
type (Activity)
min (Optional)
}
input(imaginary) {
type (Imaginary)
min (Optional)
}
}
output (Activity) {
throws {
error (NoCurrentTrip) {
on-catch {
halt {
dialog {
template ("You don't seem to be on a ride.")
}
}
}
}
}
}
}
Once the ride is over, which is checked with the condition
by the existence of a receipt
, the refresh will stop.
Your goal does not need to be an action of type RefreshActivity
to use refresh. For example, in the viv.flightStats
capsule, the goal is the structure concept FlightStats
. However, if you have a transactional capsule and you need to access information from the 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 Giving Updates with Activity Cards.