check whether app is in foreground before starting service
This commit is contained in:
parent
bb89756815
commit
ee4dd38bbe
2 changed files with 12 additions and 1 deletions
|
@ -1,5 +1,6 @@
|
||||||
package deckers.thibault.aves.channel.calls
|
package deckers.thibault.aves.channel.calls
|
||||||
|
|
||||||
|
import android.app.ActivityManager
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import androidx.work.ExistingWorkPolicy
|
import androidx.work.ExistingWorkPolicy
|
||||||
import androidx.work.OneTimeWorkRequestBuilder
|
import androidx.work.OneTimeWorkRequestBuilder
|
||||||
|
@ -51,6 +52,17 @@ class AnalysisHandler(private val activity: FlutterFragmentActivity, private val
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val activityManager: ActivityManager = activity.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
|
||||||
|
val runningAppProcesses = activityManager.runningAppProcesses
|
||||||
|
if (runningAppProcesses != null) {
|
||||||
|
val importance = runningAppProcesses[0].importance
|
||||||
|
if (importance < ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
|
||||||
|
// the app is in the background
|
||||||
|
result.error("startAnalysis-background", "app is in the background (process importance=$importance)", null)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// can be null or empty
|
// can be null or empty
|
||||||
val allEntryIds = call.argument<List<Int>>("entryIds")
|
val allEntryIds = call.argument<List<Int>>("entryIds")
|
||||||
|
|
||||||
|
|
|
@ -495,7 +495,6 @@ abstract class CollectionSource with SourceBase, AlbumMixin, CountryMixin, Place
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO TLAD check whether app is in foreground before starting service
|
|
||||||
if (startAnalysisService) {
|
if (startAnalysisService) {
|
||||||
await AnalysisService.startService(
|
await AnalysisService.startService(
|
||||||
force: force,
|
force: force,
|
||||||
|
|
Loading…
Reference in a new issue