@@ -58,6 +58,8 @@ class FilePickerActivity : AppCompatActivity(), View.OnClickListener,
5858 LinkedBlockingDeque ()
5959 )
6060
61+ private var loadingFuture: Future <* >? = null
62+
6163 private val loadFileRunnable: Runnable by lazy {
6264 Runnable {
6365 val customRootPathFile = pickerConfig.customRootPathFile
@@ -144,15 +146,19 @@ class FilePickerActivity : AppCompatActivity(), View.OnClickListener,
144146 */
145147 private val selectedCount
146148 get() = listAdapter.checkedCount
149+
147150 private val maxSelectable = FilePickerManager .config.maxSelectable
151+
148152 private val pickerConfig by lazy { FilePickerManager .config }
153+
149154 private var fileListListener: RecyclerViewListener ? = null
150155 get() {
151156 if (field == null ) {
152157 field = getListener(rvList)
153158 }
154159 return field
155160 }
161+
156162 private var navListener: RecyclerViewListener ? = null
157163 get() {
158164 if (field == null ) {
@@ -178,6 +184,12 @@ class FilePickerActivity : AppCompatActivity(), View.OnClickListener,
178184 override fun onDestroy () {
179185 super .onDestroy()
180186 Log .i(TAG , " onDestroy" )
187+ try {
188+ loadingFuture?.cancel(true )
189+ loadingFuture = null
190+ } catch (e: Exception ) {
191+ Log .e(TAG , " onDestroy: " , e)
192+ }
181193 val shouldShutDownThreadPool = pickerConfig.threadPool != loadingThreadPool
182194 || pickerConfig.threadPoolAutoShutDown
183195
@@ -333,7 +345,7 @@ class FilePickerActivity : AppCompatActivity(), View.OnClickListener,
333345 }
334346 try {
335347 Log .i(TAG , " loadList in ${Thread .currentThread()} in $loadingThreadPool " )
336- loadingThreadPool.submit(loadFileRunnable)
348+ loadingFuture = loadingThreadPool.submit(loadFileRunnable)
337349 } catch (e: RejectedExecutionException ) {
338350 Log .e(TAG , " submit job failed" )
339351 }
0 commit comments