Waiting for a function to finish execution and using the results

后端 未结 2 763
伪装坚强ぢ
伪装坚强ぢ 2021-01-25 12:05

Here\'s the scenario

I have an activity(A) which has a button and textview. I have another class(B) with methods for performing various functions. After creating an inst

2条回答
  •  再見小時候
    2021-01-25 12:18

    Android development is event driven, you should normally not block threads waiting for a result (at least not the main/ui thread since your application then might be considered as not responding).

    It's better to create a callback interface, and let the metod that takes a long time to execute, invoke a method on that inteface when the computation has been completed.

    Btw, your post indicates that the computation already is asynchronous? You would otherwise have the result when the method has completed.

提交回复
热议问题