Accessing views from other thread (Android)

前端 未结 5 1015
小蘑菇
小蘑菇 2020-12-19 07:21

I\'m developing an android application, and I have a button which starts/pauses certain simulation process. While this process is running, I need to output some data from it

5条回答
  •  借酒劲吻你
    2020-12-19 07:35

    You can handle it in many ways,

    1. Try to use AsyncTask in this, your background work done in doInBackGround() method, and your UI will not block and you can also access the views of Activity from where you call AsyncTask by its context via publishProgress() and onProgressUpdate() .

    2. If you are using a simple Thread then using Handler or message or runOnUiThread you can update the view of main thread.

    but, in your way I think AsyncTask is best for you.

提交回复
热议问题