Appearance
Classic Workouts
Classic workouts are rendered through GoFragment. Use this flow for block-based sessions where TrainingKit displays each exercise, rest, prompt, and completion screen inside the Android SDK UI.
Capabilities
- Navigate through exercises
- Display exercise details
- Pause and resume flow
- Voice coach guidance support
- Workout save-state callbacks
Create the fragment
Fetch the classic workout payload from the TrainingKit GraphQL API, prepare any JSON configuration your integration needs, then attach the fragment to your activity container.
kotlin
val goFragment = GoFragment.newInstance(
workoutContent, // GraphQL payload
workoutConfig, // JSON configuration
jwtToken // JWT token
)GoFragment.newInstance also accepts an optional workoutFileId argument. Provide a stable value when you want TrainingKit to restore an interrupted workout with the same saved state. If omitted, the SDK generates a random identifier.
kotlin
val goFragment = GoFragment.newInstance(
workoutContent = workoutContent,
extraContent = workoutConfig,
JwtToken = jwtToken,
workoutFileId = workoutContent.optString("id")
)Host activity integration
- Add
goFragmentto your activity layout or container. - Keep the host activity alive for the full workout flow.
- Implement
TrainingKitInterfaceon the host activity before displaying the fragment. - Configure texts/behavior through JSON keys before fragment creation. See Configuration Options.
- Forward Android back actions to TrainingKit when you want the SDK to show its own quit or pause flow.
- Keep the screen on while the workout is visible.
kotlin
override fun onResume() {
super.onResume()
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
}
override fun onStop() {
super.onStop()
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
}If your integration uses Android 13 back handling or OnBackPressedDispatcher, dispatch GoAction.Workout.BackPressed() instead of closing the activity immediately. This lets TrainingKit decide whether to pause, confirm quit, or close.
Handle completion
Classic workouts report completion through the TrainingKitInterface implemented by your host activity.
kotlin
override fun saveWorkout(state: SaveWorkoutState) {
// The workout completed. Persist state, then notify TrainingKit/save UI.
}
override fun goNextScreen(state: SaveWorkoutState?) {
// Continue to the next host-app screen after the workout flow.
}
override fun closeGoMode(state: SaveWorkoutState?) {
// The user closed the workout before completing it.
finish()
}
override fun shouldDisplayCloseButton(): Boolean {
// Return true when TrainingKit should display its close button.
return true
}
override fun trackEvent(
name: Tracking.Event,
properties: Map<Tracking.Property, String>?
) {
// Optional: forward TrainingKit analytics metadata.
}Use saveWorkout as the source of truth for completed workout results. Use closeGoMode for exits that do not produce a completed save, and trackEvent for analytics-only events.
SaveWorkoutState contains the workout id, title, duration, exercise evaluations, block timing, calories, equipment weights, difficulty changes, and start time. Persist the fields needed by your backend before navigating away from the workout screen.
Optional host hooks
TrainingKitInterface also exposes optional hooks for premium access, ads, recommendations, assets, music, and token errors. Implement them when your product uses the corresponding capability.
| Hook | Usage |
|---|---|
displayCheckout() | Open your purchase flow when the user taps a premium unlock action. |
displayAds(blockId: String) | Show your ad flow for an unlockable premium block. |
fetchAllRecommendations(unlockedBlockId: String?) | Refresh workout recommendations, optionally after a block has been unlocked. |
getAssetsPromise() | Provide downloaded asset-pack location data when your app manages workout assets. |
getAvailablePlaylists() | Return music playlists available to the workout settings screen. |
getPlaylists() | Return audio files for the currently enabled playlists. |
enableMusicStyle(value: Any?) | Persist that a music style was enabled. |
disableMusicStyle(value: Any?) | Persist that a music style was disabled. |
onTokenVerificationError(exception: JWTVerificationException) | Handle JWT verification failures from the SDK. |
