Android how to putExtra to an activity from TabHost activity?

梦想的初衷 提交于 2019-12-23 18:53:21

问题


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...


回答1:


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.



来源:https://stackoverflow.com/questions/7663209/android-how-to-putextra-to-an-activity-from-tabhost-activity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!