开发者

How to notify a change from one tab to another?

开发者 https://www.devze.com 2023-03-24 12:08 出处:网络
I am stuck on this one. I am making a call to a service which updates data in one tab. However, when I switch to another tab I want to notify the tab I switched to that the result has changed, and al

I am stuck on this one. I am making a call to a service which updates data in one tab.

However, when I switch to another tab I want to notify the tab I switched to that the result has changed, and also update data on that ta开发者_StackOverflow社区b to make a different service call.

Is there any way I can call setResult in the first tab so that, when the second tab is resumed, it will update its data depending on the result code in onActivityResult()?


Just have a reference to that activity or the tab host and call the setResult method from your service.

Most of the code should be in the Tab Host, and then you use callback methods from the tabhost once the event has happended. Check out Update tabs from a tab's activity in a Android TabHost. You might want to switch them to views instead of activities.


Consider you have two tabs A and B. Now you're moving from tab A to Tab B. So onPause of Tab A and onResume of Tab B will be called. Now you did some changes from Tab B and you want them to be reflected when you move to Tab A.

So again when you move to Tab A onResume of Tab A will be called.

So you can do the functionality in this onResume method.

0

精彩评论

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