开发者

How to update UI when an alarm broadcast receiver receive the event?

开发者 https://www.devze.com 2023-02-15 16:24 出处:网络
In my application there\'s a main activity which might be show on the top or in the background, and there\'s a broast receiver who receive the alarm event.

In my application there's a main activity which might be show on the top or in the background, and there's a broast receiver who receive the alarm event.

My main activity and the receiver seems to be two instances, and I can't call a static member in main activity (e.g.listview) to update itself from the receiver. It this correct?

So, how do i notify my current main activity to update itself?

p.s. I don't want to show my main activity开发者_开发问答 if it's not currently on top.

Thanks a lot.


One mechanism I have seen used to provide a good solution is a Broadcast Receiver. You can read more about the solution in the Common Tasks area of the android documentation.

Edit: Although, rereading your question, I'm not positive I have enough information. If your receiver is already in your activity, then you just need to use the runOnUi(Runnable) call from the Activity to allow you to update the UI.

0

精彩评论

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