Launching activities within a tab in Android

It is possible to launch activities within tabs. Therefore set the tabspec content to an ActivityGroup instead of a regular Activity.

tabHost.addTab(tabHost.newTabSpec("Tab")
                .setIndicator("Tab")
                .setContent(new Intent(this, YourActivityGROUP.class)
                 .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)));

From within that ActivityGroup you can then start another Activity like this that only updates the contentview of the tab you’re in.

class YourActivityGROUP extends ActivityGroup{

@Override
protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);

      //you van get the local activitymanager to start the new activity

      View view = getLocalActivityManager()
                                .startActivity("ReferenceName", new
      Intent(this,YourActivity.class)
                                .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
                                .getDecorView();
       this.setContentView(view);

   }
}

Leave a Comment