Skip to content

Commit 95882c5

Browse files
adil192Dev-hwang
authored andcommitted
Fix: Also override onTimeout(int, int) for android 15
Android 15 introduces a new timeout behavior to dataSync for apps targeting Android 15 (API level 35) or higher. This behavior also applies to the new mediaProcessing foreground service type. The system permits an app's dataSync services to run for a total of 6 hours in a 24-hour period, after which the system calls the running service's Service.onTimeout(int, int) method (introduced in Android 15). At this time, the service has a few seconds to call Service.stopSelf(). When Service.onTimeout() is called, the service is no longer considered a foreground service. If the service does not call Service.stopSelf(), the system throws an internal exception. https://developer.android.com/about/versions/15/behavior-changes-15#datasync-timeout
1 parent 5a7fc06 commit 95882c5

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ android {
3030
namespace 'com.pravera.flutter_foreground_task'
3131
}
3232

33-
compileSdk 34
33+
compileSdk 35
3434

3535
compileOptions {
3636
sourceCompatibility JavaVersion.VERSION_1_8

android/src/main/kotlin/com/pravera/flutter_foreground_task/service/ForegroundService.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,12 @@ class ForegroundService : Service() {
224224
stopForegroundService()
225225
}
226226

227+
@RequiresApi(Build.VERSION_CODES.VANILLA_ICE_CREAM)
228+
override fun onTimeout(startId: Int, fgsType: Int) {
229+
super.onTimeout(startId, fgsType)
230+
stopForegroundService()
231+
}
232+
227233
private fun loadDataFromPreferences() {
228234
foregroundServiceStatus = ForegroundServiceStatus.getData(applicationContext)
229235

0 commit comments

Comments
 (0)