diff --git a/quickstep/src/com/android/quickstep/views/RecentsView.java b/quickstep/src/com/android/quickstep/views/RecentsView.java index 3e4b953b5b..53b1301f8f 100644 --- a/quickstep/src/com/android/quickstep/views/RecentsView.java +++ b/quickstep/src/com/android/quickstep/views/RecentsView.java @@ -2771,6 +2771,7 @@ public abstract class RecentsView< } if (enableRefactorTaskThumbnail()) { mRecentsViewModel.onReset(); + getTaskViews().forEach(TaskView::cancelJobs); } } diff --git a/quickstep/src/com/android/quickstep/views/TaskView.kt b/quickstep/src/com/android/quickstep/views/TaskView.kt index e5e4536e73..c52b26bb6f 100644 --- a/quickstep/src/com/android/quickstep/views/TaskView.kt +++ b/quickstep/src/com/android/quickstep/views/TaskView.kt @@ -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") }