# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1622226495 0 # Node ID 6b5057dd6b8e5a9894e81161f553f78f87305def # Parent 2c15b3d41fe423f1f5c38264e58c25721d3ad491 Android: Experimental change for the new file browser... require it be on secondary... thread, and use condition for the UI thread to trigger execution on result. diff -r 2c15b3d41fe4 -r 6b5057dd6b8e android/DWindows.kt --- a/android/DWindows.kt Fri May 28 01:02:07 2021 +0000 +++ b/android/DWindows.kt Fri May 28 18:28:15 2021 +0000 @@ -742,6 +742,8 @@ private var menuBar: DWMenu? = null private var defaultItem: View? = null private var fileURI: Uri? = null + private var fileLock = ReentrantLock() + private var fileCond = threadLock.newCondition() // Our version of runOnUiThread that waits for execution fun waitOnUiThread(runnable: Runnable) @@ -3225,9 +3227,15 @@ override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) - if(requestCode == 100 && resultCode == Activity.RESULT_OK) { - fileURI = data!!.data - throw java.lang.RuntimeException() + if(requestCode == 100) { + fileLock.lock() + if(resultCode == Activity.RESULT_OK) { + fileURI = data!!.data + } else { + fileURI = null + } + fileCond.signal() + fileLock.unlock() } } @@ -3235,20 +3243,24 @@ { var retval: String? = null - waitOnUiThread { - val fileintent = Intent(Intent.ACTION_GET_CONTENT) - fileintent.type = "text/plain" - fileintent.addCategory(Intent.CATEGORY_OPENABLE) - startActivityForResult(fileintent, 100) + // This can't be called from the main thread + if(Looper.getMainLooper() != Looper.myLooper()) { + fileLock.lock() + waitOnUiThread { + val fileintent = Intent(Intent.ACTION_GET_CONTENT) + fileintent.type = "text/plain" + fileintent.addCategory(Intent.CATEGORY_OPENABLE) + startActivityForResult(fileintent, 100) + } + + // Wait until the intent finishes. + fileCond.await() + fileLock.unlock() + + if(fileURI != null) { + retval = getUriRealPath(this, fileURI) + } } - - // loop till a runtime exception is triggered. - try { - Looper.loop() - } catch (e2: RuntimeException) { - } - - retval = getUriRealPath(this, fileURI) return retval }