• Android GroupActivity 管理子activity跳转和回退


    public class ModelGroupTab extends ActivityGroup {
    
        LinearLayout container;
        //用于管理本Group中的所有Activity       
        public static ActivityGroup group;  
        @Override  
        protected void onCreate(Bundle savedInstanceState) {  
            super.onCreate(savedInstanceState);  
          //  setContentView(R.layout.modeltabgroup);
           // container=(LinearLayout)findViewById(R.id.modeltabgroup);
            group = this;  
        }  
      
        @Override  
        public void onBackPressed() {         
            //把后退事件交给子Activity处理  
            group.getLocalActivityManager().getCurrentActivity().onBackPressed();  
        }  
      
        @Override  
        protected void onStart() {  
            super.onStart();  
            //要跳转的Activity  
            Intent intent = new Intent(this, A_Activity.class);  
            // 把Activity转换成一个Window,然后转换成View  
            Window w = group.getLocalActivityManager().startActivity(  
                    "FirstActivity", intent);  
            View view = w.getDecorView();  
            //container.removeAllViews();
            //container.addView(view);
            //设置要跳转的Activity显示为本ActivityGroup的内容  
            group.setContentView(view);  
        }  
    }

    把按返回按钮的事件交给子activity处理

    初始化要跳转到的activity

    LocalActivityManager通过startActivity(String id, Intent intent),可以与指定的Actiivty绑定,

    @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                   Intent intent = new Intent(A_Activity.this, B_Activity.class);  
                   // 把Activity转换成一个Window,然后转换成View  
                   Window w = ModelGroupTab.group.getLocalActivityManage().startActivity("BActivity",intent);  
                   View view = w.getDecorView();
                   LinearLayout container=(LinearLayout) ModelGroupTab.group.getWindow().findViewById(R.id.modeltabgroup);
                
                   //设置要跳转的Activity显示为本ActivityGroup的内容  
                   ModelGroupTab.group.setContentView(view);  
            }

    Aactivity跳转到Bactivity

    @Override
        public void onBackPressed() {
            // TODO Auto-generated method stub
            //super.onBackPressed();
            
              Intent intent = new Intent(B_Activity.this, A_Activity.class);  
             
              // 把Activity转换成一个Window,然后转换成View  
              
              String id=ModelGroupTab.group.getLocalActivityManager() .getCurrentId();
    
              Window w = ModelGroupTab.group.getLocalActivityManager()  
                      .startActivity("A_Activity",intent);  
              View view = w.getDecorView();  
              
                        //设置要跳转的Activity显示为本ActivityGroup的内容  
              ModelGroupTab.group.setContentView(view);  
              System.out.println("activity "+id+" finsih");
              ModelGroupTab.group.getLocalActivityManager().destroyActivity(id, true);
    
             
        }

    Bactivity回退到Aactivity,覆写

    public void onBackPressed() 

    写完设置跳转的代码后,finish当前activity,先获得当前绑定的activity id,然后通过

    ModelGroupTab.group.getLocalActivityManager().destroyActivity(id, true);销毁

  • 相关阅读:
    Win7最高权限问题
    UNEDI/FACT基础知识
    关于display
    sql server 复制需要有实际的服务器名称才能连接到服务器
    ANSI ASC X12标准学习指南
    Eclipse插件的安装方法
    PB DataWindow的38个技巧
    Java API 帮助文档中英文版下载
    用快捷方式在Windows2008下安装新字体的技巧
    sqlserver 性能分析报表
  • 原文地址:https://www.cnblogs.com/cschen/p/3381352.html
Copyright © 2020-2023  润新知