###前提・実現したいこと
スレッドの中で画像データの受信とImageViewに受信した画像の表示を行っています。
UIスレッド以外ではUIをいじれないということなので、runOnUiThreadでImageViewへの表示を行っています。
画像を表示処理の完了を待ちたいのですがどのようにしたらよいのでしょうか?
###該当のソースコード
kotlin
1Thread(Runnable { 2 while(!isStop) { 3 4 /* 5 * 画像データを受信します。 6 */ 7 receiveBuff = null 8 9 var imageData : ByteArray? = null 10 var timeout = 500 11 12 while (true) { 13 try { 14 Thread.sleep(100) 15 if(timeout < 0) { 16 break 17 } else if(receiveBuff != null) { 18 imageData = receiveBuff?.copyOf() 19 break 20 } 21 } catch (e: InterruptedException) { 22 e.printStackTrace() 23 } catch (e: Exception) { 24 e.printStackTrace() 25 } 26 27 timeout-- 28 } 29 30 this.imageData = imageData 31 32 33 /* 34 * 受信した画像データをViewに表示します。 35 */ 36 runOnUiThread { 37 var bmp : Bitmap? = null 38 var imageSize = 0 39 if(this.imageData != null) { 40 imageSize = this.imageData?.size ?: 0 41 bmp = BitmapFactory.decodeByteArray(this.imageData, 0, imageSize) 42 } 43 44 if(imageSize == 0) { 45 Toast.makeText(applicationContext, "imageData size is 0.", Toast.LENGTH_SHORT).show() 46 return@runOnUiThread 47 } 48 49 // BitmapオブジェクトをImageViewに表示 50 val iv = ivScreenImage as ImageView 51 iv.setImageBitmap(bmp) 52 53 if(iv is CustomScaleImageView) { 54 iv.fitToFitScale() 55 } 56 } 57 } 58}).start()
###試したこと
runOnUiThreadの処理部分をRunnableで抜き出して(myRunnableとしました)
runOnUiThread(myRunnable) myRunnable.wait()
みたいな感じでできるのかなと思いましたが、wait()が認識されず赤字になってしまいました。
###補足情報(言語/FW/ツール等のバージョンなど)
Android studio 3.0.1
kotlin 1.2.10

バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/03/13 04:06
2018/03/13 16:02
2018/03/14 02:07
2018/03/14 16:58
2018/03/15 00:44