开发者

Updating a TextView in an Activity from a Service in Android?

开发者 https://www.devze.com 2023-03-27 13:32 出处:网络
I have a T开发者_如何学CextView in an Activity which I wish to update from a service. How can this be achieved?You could use a BroadcastReceiver. An intent should be fired from a service and TextView.

I have a T开发者_如何学CextView in an Activity which I wish to update from a service. How can this be achieved?


You could use a BroadcastReceiver. An intent should be fired from a service and TextView.setText() called in the onReceive() method of the BroadcastReceiver.


Yes you can. I would suggest creating some kind of interface that the service feeds updates to. The activity will implement this interface and set itself as a 'listener' on the service (removing itself in onDestroy).

0

精彩评论

暂无评论...
验证码 换一张
取 消