TabActivity打开Intent与Android中的ACTION_View

时间:2012-08-16 06:29:56

标签: android tabactivity activitygroup

面对TabActivity的问题,我有5个标签可能tabActivity到一个标签我正在使用Intent与ACTION_VIEW播放YouTube视频。当我第一次选择该选项卡时,它打开浏览器并播放我的视频,但下次它没有响应我。我尝试了很多。如果您有任何解决方案,请与我分享。

这是代码形式TabActivit

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        getWindow().setWindowAnimations(0);

        tabHost = getTabHost();
        tabHost.setup();

        extras = getIntent().getExtras();

        int isFetched = extras.getInt("IsFetched", 0);

        Resources res = getResources();

        Intent t0 = new Intent(this, HomeTabGroup.class);
        t0.putExtra("IsFetched",isFetched);

        tabHost.addTab(tabHost.newTabSpec("Home")
                .setIndicator(prepareTabView(this, "0",  res
                        .getDrawable(R.drawable.hometab)))
                .setContent(t0));

        tabHost.getTabWidget().setBackgroundResource(R.drawable.bg_nav);
       // Intent t1 = new Intent(this, SurprizeMeTabGroup.class);
        Intent t1 = new Intent(this, SurpriseScreen.class);
        tabHost.addTab(tabHost.newTabSpec("surprise")
                .setIndicator(prepareTabView(this, "1",  res
                        .getDrawable(R.drawable.surprizetab)))
                .setContent(t1));




        tabHost.setCurrentTab(0);

        HomeTabGroup.group.tabHost = this.tabHost;

以下是我的SurpizeScreen的代码

 @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.surprise_screen);
        Intent intent = getYouTubeIntent(this, "http://www.youtube.com/watch?v=6KKXVbJCKEo");
        startActivity(intent);


 }

1 个答案:

答案 0 :(得分:0)

Finlay经过多次尝试后找到了解决方案。 用TabActivity覆盖扩展类的onchange方法并调用ACTION_VIEW Intent

    @Override
            public void onTabChanged(String tabId) {
                if(tabId.equals("surprise")) {
                    startActivity(getYouTubeIntent(MainTabbarScreen.this, "http://www.youtube.com/watch?v=6KKXVbJCKEo"));
                }
             }
        });