Merge "Also cancel TaskView collection Jobs when Overview is not on screen." into main
This commit is contained in:
committed by
Android (Google) Code Review
commit
982c2abef5
@@ -2771,6 +2771,7 @@ public abstract class RecentsView<
|
||||
}
|
||||
if (enableRefactorTaskThumbnail()) {
|
||||
mRecentsViewModel.onReset();
|
||||
getTaskViews().forEach(TaskView::cancelJobs);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -892,17 +892,21 @@ constructor(
|
||||
return thumbnailPosition
|
||||
}
|
||||
|
||||
override fun onDetachedFromWindow() =
|
||||
traceSection("TaskView.onDetachedFromWindow") {
|
||||
super.onDetachedFromWindow()
|
||||
if (enableRefactorTaskThumbnail()) {
|
||||
// The jobs are being cancelled in the background thread. So we make a copy of the
|
||||
// list to prevent cleaning a new job that might be added to this list during
|
||||
// onAttach or another moment in the lifecycle.
|
||||
val coroutineJobsToCancel = coroutineJobs.toList()
|
||||
coroutineJobs.clear()
|
||||
override fun onDetachedFromWindow() {
|
||||
super.onDetachedFromWindow()
|
||||
cancelJobs()
|
||||
}
|
||||
|
||||
fun cancelJobs() =
|
||||
traceSection("TaskView.cancelJobs") {
|
||||
// The jobs are being cancelled in the background thread. So we make a copy of the
|
||||
// list to prevent cleaning a new job that might be added to this list during
|
||||
// onAttach or another moment in the lifecycle.
|
||||
val coroutineJobsToCancel = coroutineJobs.toList()
|
||||
coroutineJobs.clear()
|
||||
if (coroutineJobsToCancel.isNotEmpty()) {
|
||||
coroutineScope.launch(dispatcherProvider.background) {
|
||||
traceSection("TaskView.onDetachedFromWindow.cancellingJobs") {
|
||||
traceSection("TaskView.cancelJobs.cancellingJobs") {
|
||||
coroutineJobsToCancel.forEach {
|
||||
it.cancel("TaskView detaching from window")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user