Skip to main content

Android SDK best practice

Mobile application performance is critical to your business. Our technology is focused on improving your customer's experience with your app. As such, screen performance is a core component of our solutions. To boost engagement and conversion rates, we employ several approaches to minimize screen load times.

Jetpack Compose Component

Starting from major version 4 of the Rokt Android SDK, you can add a Rokt layout by utilizing the RoktLayout composable. This removes the need to call Rokt.execute and supports a more modern declarative integration using Compose as outlined in Add a placement.

Adding the component

import com.rokt.roktsdk.RoktLayout

@Composable
fun MainScreen(modifier: Modifier = Modifier) {
Column(
modifier = modifier
.background(Color.LightGray)
.padding(8.dp),
) {
// if application supports only light mode
val config = remember {
RoktConfig.Builder().colorMode(RoktConfig.ColorMode.LIGHT).build()
}
RoktLayout(
sdkTriggered = true,
viewName = "RoktExperience",
attributes = mapOf(
"email" to "j.smith@example.com",
"firstname" to "Jenny",
"lastname" to "Smith",
"mobile" to "(323) 867-5309",
"postcode" to "90210",
"country" to "US"
),
location = "RoktEmbedded1", // If using an embedded layout
onLoad = {},
onUnload = {},
config = config,
onShouldShowLoadingIndicator = {},
onShouldHideLoadingIndicator = {},
)
}
}
note

You can use the RoktLayout composable for both embedded and overlay layouts.

Using App Configurations

Applications can now pass the configuration settings from their own application environment. This allows Rokt SDK to use application's custom configurations instead of relying solely on system defaults.

import com.rokt.roktsdk.Rokt

// if application supports only Light Mode.
val roktConfig = RoktConfig.Builder().colorMode(RoktConfig.ColorMode.LIGHT).build()
Rokt.execute(
// other params,
config = roktConfig,
)

ColorMode object

ValueDescription
LIGHTApplication is in Light Mode
DARKApplication is in Dark Mode
SYSTEMApplication defaults to System Color Mode

Using Font Typefaces

If you are using your own font typefaces as outlined in Initialize the Android SDK, you need to pass a map of weak references to your typeface objects in execute.

import com.rokt.roktsdk.Rokt;

class ConfirmationActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
...

Map<String,String> attributes = new HashMap<String, String>();

attributes.put("email", "j.smith@example.com");
attributes.put("firstname", "Jenny");
attributes.put("lastname", "Smith");
attributes.put("mobile", "(323) 867-5309");
attributes.put("postcode", "90210");
attributes.put("country", "US");

Map<String, WeakReference<Typeface>> fontTypefaces = new HashMap<>();

fontTypefaces.put("Arial-Bold", new WeakReference<>(yourTypefaceObject));

Rokt.INSTANCE.execute("RoktExperience",
attributes,
new Rokt.RoktCallback() {
@Override
public void onLoad() {
}
@Override
public void onUnload(Rokt.UnloadReasons unloadReasons) {
}
@Override
public void onShouldHideLoadingIndicator() {
}
@Override
public void onShouldShowLoadingIndicator() {
}
},
fontTypefaces
)
...
}
}

For more information see how-to section.

Was this article helpful?