简体   繁体   中英

How to notify a change from one tab to another?

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 tab 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() ?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM