Activity跳转到 TabActivity的子页面

。。。。。。随手记下,这个东西用到的并不是太多


还用上次写的TabActivity那个demo来说吧点击打开链接


在TabActivity 中的oncreate() 中添加 广播,代码如下:


//注册广播
        IntentFilter filter = new IntentFilter();
        filter.addAction("com.example.one");
        filter.addAction("com.example.two");
        filter.addAction("com.example.three");
        filter.addAction("com.example.four");
        TestRevice revice = new TestRevice();
        registerReceiver(revice, filter);

加个内部类


class TestRevice extends BroadcastReceiver {

        @Override
        public void onReceive(Context context, Intent intent) {
            //实现跳转
            if (intent.getAction().equalsIgnoreCase("com.example.one")){
                tabHost.setCurrentTabByTag("home");         
            }
            if (intent.getAction().equalsIgnoreCase("com.example.two")){
                tabHost.setCurrentTabByTag("contrl");
            }
            if (intent.getAction().equalsIgnoreCase("com.example.three")){
                tabHost.setCurrentTabByTag("suiyi");
            }
            if (intent.getAction().equalsIgnoreCase("com.example.four")){
                tabHost.setCurrentTabByTag("set");
            }

        }

    }


最后在其他Activity 跳转的时候,发广播跳转即可


// 发送广播
				Intent intent = new Intent("com.example.three");
				sendBroadcast(intent);





猜你喜欢

转载自blog.csdn.net/mapeifan/article/details/53083216