Jim
Jim

Reputation: 1986

Force Tabhost to initiate Activity (refresh)

To put it simply. From a context menu on a TabActivity how can I initiate executing the intent for the current tab? I am trying to force a refresh.

The tabs all initiate activities displaying a subset of people names. While in one list you call up an edit activity which allows you to associate the name to one of the other lists in the TabHost. Using the back button to get back to the tabhost (onResume fires) and the list has not updated. I would like to have a context menu item to refresh the current tab.

I know about using one activity for all the views in a tabhost but for many reasons I have not chosen that method.

Upvotes: 0

Views: 4495

Answers (2)

Anthony Graglia
Anthony Graglia

Reputation: 5435

You can also try adding a flag to the intent when you set up the tabs in the first place.

    Intent i = new Intent().setClass(this, YourClass.class)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    TabHost.TabSpec spec = tabHost.newTabSpec("name")
.setIndicator("Class",res.getDrawable(R.drawable.ic_tab_something))
.setContent(intent);

    Tabhost tabHost.addTab(spec);

Upvotes: 2

Scoobler
Scoobler

Reputation: 9719

I think due to the activity lifecycle, you will have some problems 'restarting' the activity (Activity lifecycle - startActivity()) - if you were to move any logic you have inside the onCreate method into another method, then call the method from onCreate and onResume, so it rebuilds the tab content for you.

Alternatively you could add a menu item to call this method, so onCreate calls the logic method on first run, and your user can call it from the menu to refresh the contents.

Upvotes: -1

Related Questions