How can I update information in an Android Activity from a background Service

前端 未结 5 1968
北海茫月
北海茫月 2020-11-29 17:06

I am trying to create a simple Android application that has a ActivityList of information, when the application starts, I plan to start a Service that will be constantly cal

5条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-29 17:08

    You will have a background thread running that calculates the changes in the list. This thread now needs a possibility to notify the GUI that the list was updated.

    You can use some kind of ArrayAdapter to get the data into the ListView. The ArrayAdapter has a method called adpater.notifyDataSetChanged() every time you call this method the adapter will see that the corresponding data has changed and then notify the listview that it should update at the next possibility.

提交回复
热议问题