| .. | ||
| src/main | ||
| build.gradle.kts | ||
| README.md | ||
KTag Sample Subapp
A minimal Jetpack Compose subapp template for creating new KTag applications.
Overview
The Sample subapp provides a starting point for creating new subapps in the KTag ecosystem. It demonstrates the minimal required structure and can be copied as a template for new functionality.
Architecture
The simplest possible subapp structure:
┌─────────────────────────────────────────────────────────┐
│ SampleActivity │
│ (Compose Host) │
│ • Single "Hello World" screen │
└─────────────────────────────────────────────────────────┘
File Structure
src/main/java/club/clubk/ktag/apps/sample/
├── SampleActivity.kt # Main activity with Compose UI
├── SampleSubApp.kt # Subapp registration
└── SampleInitializer.kt # Startup initializer
Creating a New Subapp
To create a new subapp based on this template:
- Copy the module: Duplicate
subapp-sampledirectory - Rename the package: Update package name in all files
- Update build.gradle.kts: Change namespace
- Register the subapp: Update
SampleSubAppwith new ID, name, icon - Add to settings.gradle.kts: Include new module
- Add dependency: Include in main app's dependencies
Required Components
SubApp Interface
Every subapp must implement the SubApp interface:
class MySubApp : SubApp {
override val id = "myapp" // Unique identifier
override val name = "My App" // Display name
override val icon = R.drawable.ic_myapp // Launcher icon
override fun createIntent(context: Context): Intent {
return Intent(context, MyActivity::class.java)
}
}
Initializer
Register the subapp at startup:
class MyInitializer : Initializer<Unit> {
override fun create(context: Context) {
SubAppRegistry.register(MySubApp())
}
override fun dependencies(): List<Class<out Initializer<*>>> = emptyList()
}
AndroidManifest.xml
Declare the activity and initializer:
<activity android:name=".MyActivity" android:exported="false" />
<provider
android:name="androidx.startup.InitializationProvider"
android:authorities="${applicationId}.androidx-startup">
<meta-data
android:name=".MyInitializer"
android:value="androidx.startup" />
</provider>
Optional Features
For more complex subapps, consider adding:
| Feature | Reference |
|---|---|
| Settings | See subapp-koth or subapp-medic |
| MQTT | Implement SettingsSubApp interface |
| BLE | See subapp-bletool or subapp-koth |
| USB Serial | See subapp-terminal |
| ViewModel | See subapp-koth or subapp-medic |
Dependencies
- Jetpack Compose (Material3)
- AndroidX Startup (for initialization)