Search code examples
androidandroid-activityandroid-tabhost

Android how to putExtra to an activity from TabHost activity?


I have a little problem with sending an extra from one activity to another. I have let's say FirstActivity which starts TabActivity, where I have 5 tabs. When I send putExtra(), from FirstActivity to TabActivity, there is no problem, but I need to send that extra to the Activity, which holds first tab of TabHost. I'm using this code :

TabActivity.class :

int collId = getIntent().getIntExtra("collection_id", 0);
Log.i("Collection ID","Collection ID from SingleCollection.class : "+collId);

intent = new Intent(this, Collection.class);
intent.putExtra("collection_id", collId);

spec = tabHost.newTabSpec("collection").setIndicator("Collection",
                  res.getDrawable(R.drawable.ic_tab_collection))
              .setContent(intent);
tabHost.addTab(spec);

but it's not really working. I'm not receiving the extra on Collection.class.

So my question is how can I send extra to a content of a tab in TabHost. Hope you understand me...


Solution

  • From the child activity you can call getParent().getIntent() to obtain TabActivity's intent, so you don't need to put extra in the way you are doing this.