Search code examples
androidandroid-tabsonactivityresult

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


Solution

  • 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.