把当前任务放入后台

  用Activity.moveTaskToBack()把当前任务放入后台,详细看注释:
    /**
     * Move the task containing this activity to the back of the activity
     * stack.  The activity's order within the task is unchanged.
     * 把该activity所在的task移到栈底,顺序不变
     * @param nonRoot If false then this only works if the activity is the root
     *                of a task; if true it will work for any activity in
     *                a task.
     * nonRoot:false:当该activity是root activity才有用,true:所有的activity都有用
     * @return If the task was moved (or it was already at the
     *         back) true is returned, else false.
     */
    public boolean moveTaskToBack(boolean nonRoot) {
        try {
            return ActivityManagerNative.getDefault().moveActivityTaskToBack(
                    mToken, nonRoot);
        } catch (RemoteException e) {
            // Empty
        }
        return false;
    }

上边的mToken是IBinder类型,代表该Activity与ActivityManagerService进行IPC通信(进程间通信),直接看ActivityManagerService源码,如下

    /**
     * Moves an activity, and all of the other activities within the same task, to the bottom
     * of the history stack.  The activity's order within the task is unchanged.
     *  把该activity所在的task移到栈底,顺序不变
     * @param token A reference to the activity we wish to move 保存activity的引用
     * @param nonRoot If false then this only works if the activity is the root
     *                of a task; if true it will work for any activity in a task.
     * nonRoot:false:当该activity是root activity才有用,true:所有的activity都有用
     * @return Returns true if the move completed, false if not.
     */
    public boolean moveActivityTaskToBack(IBinder token, boolean nonRoot) {
        synchronized(this) {
            final long origId = Binder.clearCallingIdentity();
            int taskId = getTaskForActivityLocked(token, !nonRoot);
            if (taskId >= 0) {
                return mMainStack.moveTaskToBackLocked(taskId, null);
            }
            Binder.restoreCallingIdentity(origId);
        }
        return false;
    }


 

getTaskForActivityLocked:

    
 /**
     *  //找出token(activity)所在的栈
     * @param token 在服务端为ActivityRecord,在客户端为Activity
     * @param onlyRoot true 则只对root Activity有效,false对所有的Activity都有效
     * @return
     */
    int getTaskForActivityLocked(IBinder token, boolean onlyRoot) {
        final int N = mMainStack.mHistory.size();
        TaskRecord lastTask = null;
        for (int i=0; i<N; i++) {
            ActivityRecord r = (ActivityRecord)mMainStack.mHistory.get(i);
            if (r == token) {
                if (!onlyRoot || lastTask != r.task) {//不是root Activity时返回第一次匹配的task,否则查找root Activity对应的task
                    return r.task.taskId;
                }
                return -1;
            }
            lastTask = r.task;
        }

        return -1;
    }

mMainStack为ActivityStack,moveTaskToBackLocked如下:

    /**
     * Worker method for rearranging history stack.  Implements the function of moving all 
     * activities for a specific task (gathering them if disjoint) into a single group at the 
     * bottom of the stack.
     * 把特定的task移到栈底,并且保持顺序不变
     * If a watcher is installed, the action is preflighted and the watcher has an opportunity
     * to premeptively cancel the move.
     * 
     * @param task The taskId to collect and move to the bottom.
     * @return Returns true if the move completed, false if not.
     */
    final boolean moveTaskToBackLocked(int task, ActivityRecord reason) {
	....
 //移动到底部
        while (pos < N) {
            ActivityRecord r = mHistory.get(pos);
            if (localLOGV) Slog.v(
                TAG, "At " + pos + " ckp " + r.task + ": " + r);
            if (r.task.taskId == task) {
                if (localLOGV) Slog.v(TAG, "Removing and adding at " + (N-1));
                if (DEBUG_ADD_REMOVE) {
                    RuntimeException here = new RuntimeException("here");
                    here.fillInStackTrace();
                    Slog.i(TAG, "Removing and adding activity " + r + " to stack at "
                            + bottom, here);
                }
                mHistory.remove(pos);
                mHistory.add(bottom, r);
                moved.add(r);
                bottom++;
            }
            pos++;
        }}
	....
}


 



  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在上一个资源v1.0基础上的增强和改进! 1、解压。解压得到名为"schedule"的目录 2、打开界面。双击里面的schedule v1.1.html打开 3、解除限制。单击浏览器弹出框“允许阻止的内容”,可以看到效果 功能说明: 界面采用bootstrap和JEasyUI技术实现,提供三种任务运行规则:一次性、周期性、自定义 1、一次性(i:立即运行;ii:在规定的时间刻运行) 2、周期性(i:按小时;ii:按天 iii:按周; iv:按月(日);v: 按月(星期) ) 3、自定义(自定义功能,用户可以在前台随意定制执行计划,只要符合spring schedule cronExpression语法) 使用说明: 一: /* line 96 */ var action = "edit";//edit,add,view action用来指定用户动作,新增、编辑(修改)、查看 二: /* line 108 */ var cronExpression = "13 12 11 1 11 ? 2017";//when action is edit or view this value is useful cronExpression 的建意值: cronExpression=""; // action为空时 cronExpression =$("cronExpression");//当actionedit或view时, 把后面传过来的表达式值赋给cronExpression,界面会自动判断该如何展示 三: /* line 628 */ $("#sbmt").click(function() {//按钮事件....} 表单按钮提交事件相关代码自已根据实际情况替换修改。 亮点: i:日期选择功能使用JEasyUI的datetime,并在选择框上加了限制,不能选择早于当前的日期 ii:时间选择功能使用JEasyUI的spinner实现 iii: 自定义功能用户可以随意定制执行计划 iv:采用bootstrap的pills实现tab(选项卡)功能,界面友好 v: 打开修改界面时界面会根据后台cronExpression值智能展示tab和radio及表单值。规则:优先顺序:一次性、周期性、自定义 vi: 提交前javascript会对cronExpression进行严格的规则验证 vii: 使用javascript正则表达式实现各定时分类的匹配展示 viii: 强兼容性,集成时能与其它css样式文件兼容,尽量把schedule.html内部样式表中的样式放在目标集成界面中样式的后面避免覆盖 另:内附schdule Spring后台核心代码供后台开发参考

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值