zoukankan      html  css  js  c++  java
  • android activitygroup 使用

    创建一个activity 将返回键的处理交给子activity处理。

    public class DailyKaoshiActivityGroup extends ActivityGroup{
    /**
    * 一个静态的ActivityGroup变量,用于管理本Group中的Activity
    */
    public static ActivityGroup group;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    group = this;
    }

    @Override
    public void onBackPressed() {
    // TODO Auto-generated method stub
    // super.onBackPressed();
    //把后退事件交给子Activity处理
    group.getLocalActivityManager()
    .getCurrentActivity().onBackPressed();
    }

    @SuppressWarnings("deprecation")
    @Override
    protected void onResume() {
    // TODO Auto-generated method stub
    super.onResume();
    //把界面切换放到onResume方法中是因为,从其他选项卡切换回来时,
    //调用搞得是onResume方法

    //要跳转的界面,跳转的第一个activity
    Intent intent = new Intent(this, DailyKaoShiActivity.class).
    addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    //把一个Activity转换成一个View
    Window w = group.getLocalActivityManager().startActivity("DailyKaoShiActivity",intent);
    View view = w.getDecorView();
    //把View添加大ActivityGroup中
    group.setContentView(view);
    }
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
    //将按键的处理交给相应的子activity处理
    return group.getLocalActivityManager().getCurrentActivity().onKeyDown(keyCode, event);
    }
    }

    DailyKaoShiActivity.java中涉及的关键代码:

    Intent intent = new Intent();
    Bundle bundle = new Bundle();
    bundle.putSerializable("shitidata", shitiDatas);
    intent.putExtras(bundle);
    intent.setClass(DailyKaoShiActivity.this, DailyShiTiAtivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    //把一个Activity转换成一个View
    Window w = DailyKaoshiActivityGroup.group.getLocalActivityManager()
    .startActivity("DailyShiTiAtivity",intent);
    View view = w.getDecorView();
    //把View添加大ActivityGroup中
    DailyKaoshiActivityGroup.group.setContentView(view);

    守护
  • 相关阅读:
    27. 移除元素
    LeetCode---9.回文数
    PAT 1098 Insertion or Heap Sort (25)
    PAT 1146 Topological Order
    PAT 1147 Heaps(30 分)
    数据结构 二分查找1
    数据结构 树
    PAT 1126 Eulerian Path
    PAT 1111 Online Map (30)
    PAT 1072 Gas Station (30)
  • 原文地址:https://www.cnblogs.com/suhe/p/3457083.html
Copyright © 2011-2022 走看看