Search code examples
androidandroid-activityandroid-tabhost

Update Tabhost tab content


I have a tabhost to which I dynamically add tabs. When I add a new tab I create an intent to launch an activity as the content and add my data to the intent using putExtra.

This works fine when I create the tabs but my problem is updating the data in existing tabs. My main activity periodically updates and I need to pass the data into the various tabs.

How can I go about doing this?


Solution

  • You can update current tab when you change the tab,
    define each tab as an activity and when you want to update that just call update method of that activity:

    tabHost.setOnTabChangedListener(new OnTabChangeListener() {
    
            @Override
            public void onTabChanged(String tabId) {
                  ((yourTabActivity) getCurrentActivity()).yourUpdateMethod();
            }
      }