Skip to content

Example Integration

A complete, realistic integration for an app with a login flow. The goals:

  • Initialize Pulsate at app start.
  • Start the session after login, on the main screen — not on the login screen.
  • Show in-app messages and allow inbox access only to logged-in users.
  • Keep push notifications working for logged-out users.
class MyApp : Application() {
private lateinit var lifecycleManager: MyLifecycleManager
override fun onCreate() {
super.onCreate()
lifecycleManager = MyLifecycleManager()
val authData = PulsateAuthData(APP_ID, APP_KEY)
PulsateFactory.getInstance(authData)
}
}

2. Login screen — decide where to go, don’t start Pulsate yet

Section titled “2. Login screen — decide where to go, don’t start Pulsate yet”
class LoginFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
showSpinner()
if (loginViewModel.isUserLoggedIn()) {
navigateToMainScreen()
} else {
hideSpinner()
setupLoginScreen()
}
}
}

Why not start the session here? startPulsateSessionForAlias kicks off async network calls that can render an in-app message onto a screen that is about to be destroyed by your login navigation. Start the session on the screen the user will actually stay on.

3. Main screen — start the session and unlock Pulsate UI

Section titled “3. Main screen — start the session and unlock Pulsate UI”
class MainFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val pulsateManager = PulsateFactory.getInstance()
val alias = userRepository.currentUserId // your unique user identifier
pulsateManager.startPulsateSessionForAlias(
alias,
object : IPulsateRequestListener {
override fun onSuccess() {
// Allow in-apps + inbox for this authenticated user
pulsateManager.userHasLoggedIn()
}
override fun onError(e: Throwable?) {
e?.printStackTrace()
}
},
)
}
}

4. Lock Pulsate UI when the app leaves the foreground (optional)

Section titled “4. Lock Pulsate UI when the app leaves the foreground (optional)”

If your app logs users out when it goes to background (common in banking), mirror that in Pulsate with a ProcessLifecycleOwner observer:

class MyLifecycleManager : DefaultLifecycleObserver {
init {
Handler(Looper.getMainLooper()).post {
ProcessLifecycleOwner.get().lifecycle.addObserver(this)
}
}
override fun onStop(owner: LifecycleOwner) {
// App entered background — user must log in again next time
PulsateFactory.getInstance().userHasLoggedOut()
}
}

userHasLoggedOut() disables in-app messages and marks the user unauthorized for the inbox — but unlike logoutCurrentAlias, the device stays attached to the user, so push notifications keep working.

Logged in Logged out (userHasLoggedOut) After logoutCurrentAlias
Push notifications ✅ ✅ ❌
In-app notifications ✅ ❌ (deferred) ❌
Inbox access ✅ ❌ (blocked) ❌
Segmentation/tracking ✅ ✅ ❌

When the user logs back in, userHasLoggedIn() re-enables in-apps, shows the last bounced in-app message, marks the user authorized, and replays the last blocked inbox action. See Inbox Authorization for the fine-grained controls behind these two methods.