Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cancel loading job after onDestroy. #205

Merged
merged 1 commit into from
Jan 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class FilePickerActivity : AppCompatActivity(), View.OnClickListener,
LinkedBlockingDeque()
)

private var loadingFuture: Future<*>? = null

private val loadFileRunnable: Runnable by lazy {
Runnable {
val customRootPathFile = pickerConfig.customRootPathFile
Expand Down Expand Up @@ -144,15 +146,19 @@ class FilePickerActivity : AppCompatActivity(), View.OnClickListener,
*/
private val selectedCount
get() = listAdapter.checkedCount

private val maxSelectable = FilePickerManager.config.maxSelectable

private val pickerConfig by lazy { FilePickerManager.config }

private var fileListListener: RecyclerViewListener? = null
get() {
if (field == null) {
field = getListener(rvList)
}
return field
}

private var navListener: RecyclerViewListener? = null
get() {
if (field == null) {
Expand All @@ -178,6 +184,12 @@ class FilePickerActivity : AppCompatActivity(), View.OnClickListener,
override fun onDestroy() {
super.onDestroy()
Log.i(TAG, "onDestroy")
try {
loadingFuture?.cancel(true)
loadingFuture = null
} catch (e: Exception) {
Log.e(TAG, "onDestroy: ", e)
}
val shouldShutDownThreadPool = pickerConfig.threadPool != loadingThreadPool
|| pickerConfig.threadPoolAutoShutDown

Expand Down Expand Up @@ -333,7 +345,7 @@ class FilePickerActivity : AppCompatActivity(), View.OnClickListener,
}
try {
Log.i(TAG, "loadList in ${Thread.currentThread()} in $loadingThreadPool")
loadingThreadPool.submit(loadFileRunnable)
loadingFuture = loadingThreadPool.submit(loadFileRunnable)
} catch (e: RejectedExecutionException) {
Log.e(TAG, "submit job failed")
}
Expand Down