开发者

how to send data to multiple activities in controlled manner in Android?

开发者 https://www.devze.com 2023-01-04 16:46 出处:网络
I am working on an android application, where there are 4 activities. Activity1 is main activity and there are different buttons on that activity which can open other activities. Other 3 activities ca

I am working on an android application, where there are 4 activities. Activity1 is main activity and there are different buttons on that activity which can open other activities. Other 3 activities can als开发者_高级运维o open each other. There is a thread running in Activity1 which returns some counter. I need to show that counter on all activities.

At an specific time, the thread doesn't know which activity is at top. What is the right way to control this scenario, such that thread output should update on all activities, no matter which one is at top?


I would have that counter on a Service and I would send updates through broadcast intent.

Each Activity will register a listener to that intent on the onStart method and unregister it on onPause. This way the update will reach only the Activity that is on screen.

0

精彩评论

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