To display a full server-driven
screen, you need to use the method this.newServerDrivenIntent<BeagleActivity>()
.
this
refers to the context of the screen.This method requires the parameter ScreenRequest
.
You must follow the example below:
Make sure to list your Beagle Activity as named in your AndroidManifestfile.
In this example, you only call it BeagleActivity, but this name is defined by you when creating your BeagleActivity. In the tutorial Creating a project from scratch, it is called AppBeagleActivity
.
val intent = this.newServerDrivenIntent<BeagleActivity>(ScreenRequest("/screen"))
startActivity(intent)
To test the command above, the ScreenRequest
component requires an URL that brings the JSON with all the server-driven screen’s information that you want to display.
In this case, follow these steps:
Use the screen example on the link below that brings a JSON for a simple "\screen"
test. Just copy and paste it replacing the URL “/screen” .
https://run.mocky.io/v3/73322be2-96bf-467b-b6dc-e3fff179852c
See how the code ends up below.
val intent = this.newServerDrivenIntent<BeagleActivity>(ScreenRequest("https://run.mocky.io/v3/73322be2-96bf-467b-b6dc-e3fff179852c"))
startActivity(intent)
The ScreenRequest
is an internal Beagle class used to request which screen you want to display. You will only list the URL
attribute for the page you want to load from the BFF. However, this element has other attributes, which can be used in the transition and between screens.
To learn more about this class, check out on Screen Request
To render any Beagle component in Android, it’s necessary to inform a viewGroup
where the view corresponding to the component will be rendered, such as a FrameLayout
within an Activity
, Fragment
or DialogFragment
. See the example below:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/frame_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"/>
Now, call the loadView()
method from the frame_layout
created in the xml
and pass the Activity
and the JSON
as parameters.
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
frame_layout.loadView(
activity = this,
screenJson = "JSON HERE"
)
}
}
The loadView()
method can also receive as a parameter a Fragment
in place of Activity
and two other optional ones, following the example below:
loadView(
fragment = yourFragment,
screenJson = "JSON HERE",
screenId = "your identifier",
shouldResetContext = yourBoolean,
)
screenId
: represents an screen identifier to create the analytics when the screen is created. Default value is empty.
shouldResetContext
: when true, this clear at the time of calling the loadView
function all de context data linked to the lifecycle owner. Default value is false.
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.