ワンクリックで
android-background-execution
Expert guidance on implementing and managing background tasks in modern Android applications (API 30+).
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
Expert guidance on implementing and managing background tasks in modern Android applications (API 30+).
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
SOC 職業分類に基づく
Handling Bluetooth Low Energy, flow wrappers, and Android 12+ permissions.
Seamless integration of CameraX with Google ML Kit for vision tasks.
Deep-dive skills for banking and healthcare apps.
Use when integrating Google Gemini Nano via AICore for on-device ML.
Automated UIAutomator tests and Hardware mocking setup.
Expanding KMP shared UI to cover Compose Multiplatform edge-cases.
| name | android-background-execution |
| description | Expert guidance on implementing and managing background tasks in modern Android applications (API 30+). |
This skill provides a structured approach to implementing background work in Android, ensuring high performance, battery efficiency, and compliance with modern system restrictions (API 30 and above).
Use for persistent, deferrable work that must execute even if the app exits or the device restarts.
setExpedited(true)).Use for immediate, user-visible work that is the primary focus of the app (e.g., Music Player, Step Tracker).
foregroundServiceType in the manifest.AlarmManager)Use for exact, time-based scheduling.
setExactAndAllowWhileIdle() is for high-precision needs (e.g., clocks).| Requirement | Recommended Tool |
|---|---|
| Deferrable, restart-resilient | WorkManager (OneTime/Periodic) |
| Immediate, continues when app is closed | WorkManager (Expedited) |
| User-visible, real-time | Foreground Service |
| Specific clock time (e.g. 8:00 AM) | AlarmManager |
class SyncWorker(context: Context, params: WorkerParameters) : CoroutineWorker(context, params) {
override suspend fun doWork(): Result {
return try {
// Background logic here
Result.success()
} catch (e: Exception) {
if (runAttemptCount < 3) Result.retry() else Result.failure()
}
}
}
// Enqueueing
val constraints = Constraints.Builder()
.setRequiredNetworkType(NetworkType.CONNECTED)
.setRequiresBatteryNotLow(true)
.build()
val syncRequest = OneTimeWorkRequestBuilder<SyncWorker>()
.setConstraints(constraints)
.setBackoffCriteria(BackoffPolicy.EXPONENTIAL, 1, TimeUnit.MINUTES)
.build()
WorkManager.getInstance(context).enqueue(syncRequest)
<service
android:name=".MyService"
android:foregroundServiceType="dataSync" />
class MyService : Service() {
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
val notification = NotificationCompat.Builder(this, CHANNEL_ID)
.setContentTitle("Syncing Data")
.setSmallIcon(R.drawable.ic_sync)
.build()
ServiceCompat.startForeground(this, 1, notification, FOREGROUND_SERVICE_TYPE_DATA_SYNC)
// logic...
return START_NOT_STICKY
}
}
WorkManager handles this automatically by batching requests.setExpedited(true). Note that this has quotas.Constraints in WorkManager to prevent unnecessary wakeups when offline.WorkManagerTestInitHelper for testing workers in unit/integration tests without waiting for real-world constraints.com.example.app.data.worker or com.example.app.ui.background.com.example.app.service.Repository classes, not inside Worker or Service classes.