On this page
Static content doesn't adapt: the same tips for every user, the same practice questions every day. Generated content can adapt to a learner's level, a user's goals or a product's attributes. It can also be wrong, inappropriate, or inconsistent with your app's design, unless you engineer guardrails.
A safe generation pipeline
Structured output instead of free text
@Serializable
data class QuizQuestion(val question: String, val options: List<String>, val correctIndex: Int, val explanation: String)
@Serializable
data class Quiz(val topic: String, val questions: List<QuizQuestion>)
class QuizGenerator(private val model: GenerativeModel) {
suspend fun generate(topic: String, level: String): Quiz? {
val prompt = """
Create 5 multiple-choice questions about "$topic" for a $level Android learner.
Each question: 4 options, exactly one correct (correctIndex 0-3), a one-sentence explanation.
Use only well-established facts; avoid version-specific numbers.
""".trimIndent()
repeat(2) { // one retry on invalid output
val raw = model.generateContent(prompt).text ?: return@repeat
val quiz = runCatching { Json { ignoreUnknownKeys = true }.decodeFromString<Quiz>(raw) }.getOrNull()
if (quiz != null && quiz.isValid()) return quiz
}
return null // caller shows curated fallback quiz
}
}
/** Business-rule validation the schema can't express. */
fun Quiz.isValid(): Boolean = questions.size == 5 && questions.all { q ->
q.options.size == 4 && q.correctIndex in 0..3 &&
q.options.distinct().size == 4 && q.question.length in 10..300
}Configure the model with responseMimeType = "application/json" and a responseSchema (see structured output example) so it's constrained to your shape, then still validate rules such as distinct options.
Generate on the client or the server?
| Content | Where | Why |
|---|---|---|
| Shared by many users (product descriptions, daily tips) | Server, generated once, reviewed, cached | Cost, consistency, human review possible |
| Personalised, low-risk (practice questions for a user) | Client via Firebase AI Logic, or backend | Personalisation; validate and cache per user |
| Sensitive domains (health, finance) | Server with strict review, or don't generate | Accuracy and liability |
Moderation and policy
- Use model safety settings and an additional moderation step for user-visible content.
- Google Play's policies require apps with AI-generated content to prevent prohibited content and to provide ways for users to report offensive content. Review the current policy.
- Avoid generating content about real people, or anything that could be mistaken for authoritative advice.
Presenting generated content
- Label it ("Generated by AI"), and let users regenerate, report or hide it.
- Keep a curated static fallback so the feature never shows an empty state.
- Cache results so the same content doesn't change unexpectedly between visits.
Use cases
Learning apps
Practice questions adapted to level, validated and with explanations. See AI Study Assistant.
E-commerce
Server-generated product description drafts that merchants edit and approve.
Fitness
Workout variations from a fixed, validated exercise catalogue, with the model choosing and ordering rather than inventing exercises.
Common mistakes
- Rendering raw model text with HTML or Markdown that can break the layout or inject links.
- Trusting numbers, prices or facts generated by the model.
- Generating per screen view instead of caching, which drives cost and inconsistency.
- No reporting path for bad content.
Frequently asked questions
Can I let the model invent quiz answers?
Risky. Prefer grounding generation in your own verified content (RAG), and validate. See RAG for Android Apps.
How do I keep a consistent style?
Use a system instruction with style rules and examples, a low temperature, and a fixed schema, and evaluate samples regularly.
Do I need to disclose AI-generated content?
Labelling builds trust and may be required by platform policy or law in some contexts. Check current Play policy and local regulations.
Conclusion
Generated content is valuable when it's structured, validated, moderated, cached and labelled, with a static fallback. Generate shared content on the server, personalise carefully on the client, and never let raw model output reach users unchecked.
Next step: make your app's content findable with Build an AI-Powered Search Feature.
Official references
๐ฑ Apps built by Yunok Tech
Real Android apps on Google Play, free to download.
Walzi4K wallpapers for lock and home screenGet it โธ
NotiVaultNotification history: recover dismissed notificationsGet it โธ
Ready to build real Android applications?
Every AI feature still runs inside an Android app that has to be fast, reliable and well structured. Strengthen the Kotlin, Jetpack Compose and architecture skills that AI integrations depend on, then apply these AI concepts with confidence.
Move beyond theory and strengthen your Android development skills with Yunoktech's Android course. Learn core concepts, practical implementation, modern Android development techniques, and the reasoning behind building maintainable applications.
Explore the Android course and take your next step as an Android developer.