androidengineers.Book a session

Streaming, cancellation, and retries

Practice: Conversation and streaming

exerciseSelf-paced

Assignment: follow bytes through Stop

Read readSse, decodeGeminiEvent, and ChatRepository.stop. Predict the difference between a complete frame, an unterminated final frame, and a response that never reports STOP.

Run the behavior tests:

./gradlew :app:testDebugUnitTest --tests '*GeminiChatServiceTest' --tests '*ChatRepositoryTest'

Locate sseHandlesCrLfCommentsMultipleLinesAndUnterminatedLastFrame, eofWithoutFinishIsFailureAndPreservesPartial, and cancellingCollectionCancelsUnderlyingHttpCall. Explain what each isolates. A parser test does not prove HTTP cancellation; a canceled coroutine does not prove that a provider stopped billing.

With a configured debug app, request a longer explanation and tap Stop while text is arriving. The partial answer should remain labeled stopped. Retry, then send a follow-up after completion. Record whether a duplicate user bubble appears.

Submit a timeline containing user action, attempt invalidation, coroutine cancellation, HTTP cancellation, terminal UI state, and the next context selection. Include one race you would test if the network implementation changed. If the provider finishes too quickly to exercise Stop, use the controlled device journey rather than claiming a race was tested live.

Study guide · Hands-on codelab · Pinned Android source

YOUR LEARNING JOURNEY

0 of 23 available lessons completed

Progress saved in this browser. No account needed.
Practice: Conversation and streaming | Gemini Chat for Android with PocketChat | Android Engineers