Restarting activity on one tab in TabActivity?

I have a TabActivity. Each tab indicates auxiliary activity. This works great.

Is there any smart way to update one of the activity tabs? I just want to "restart" the activity in the table. 3, for example. Not sure of a good way to do this, other than creating update support for the activity itself or clearing all the tabs and re-creating all of them.

Thanks,

+5
source share
4 answers

A bit more dynamic solution:

LocalActivityManager manager = getLocalActivityManager();
String currentTag = tabHost.getCurrentTabTag();
Class<? extends Activity> currentClass = manager.getCurrentActivity().getClass();
manager.destroyActivity(currentTag, true);
manager.startActivity(currentTag, new Intent(this, currentClass));
+6
source

, Activity LocalActivityManager. TabActivity, getLocalActivityManager().

, destroyActivity() startActivity() Activity, , ( ). , id Activity , (, String, TabHost.newTabSpec(String)).

LocalActivityManager manager = getLocalActivityManager();
manager.destroyActivity("tab3", true);
manager.startActivity("tab3", new Intent(this, ThirdTab.class));
+4

Activity, . .

spec = tabHost  .newTabSpec("tab1")
                .setIndicator("FirstActivity")
                .setContent(new Intent(this,MyFirstActivity.class)
                .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
tabHost.addTab(spec);
+4

:

tabHost.setOnTabChangedListener(this);
public void onTabChanged(String tabId) {
        Log.d(LOG_KEY, tabId);
        LocalActivityManager manager = getLocalActivityManager();
        manager.destroyActivity("ID_1", true);
        manager.startActivity("ID_1", new Intent(this, YourMyActivity.class));
    }
+1

All Articles