android虚拟手机云之五:支持多个应用在前台

xiaoxiao2021-02-28  3

总贴 在这里。

支持多个应用在前台

先说下背景吧,很多App都有是否在前台的检测,前后台的检测方法可以看我这篇博客

一个关键点是 onPause 简单说,就是onPause不回调,App无感知的切换到后台,就成功了80%。 改动的时候,涉及到Android的窗口管理机制,但是最本质的改动还是在ActivityStack.java中

frameworks/base/services/core/java/com/android/server/am/ActivityStack.java

重点修改的函数是这个

/** * Pause all activities in either all of the stacks or just the back stacks. * @param userLeaving Passed to pauseActivity() to indicate whether to call onUserLeaving(). * @return true if any activity was paused as a result of this call. */ boolean pauseBackStacks(boolean userLeaving, boolean resuming, boolean dontWait) { boolean someActivityPaused = false; for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) { final ActivityStack stack = stacks.get(stackNdx); if (/* Add by chenyongqiang */ !isOnOtherStack(stack) && /* Add by chenyongqiang end.*/ !isFrontStack(stack) && stack.mResumedActivity != null) { if (DEBUG_STATES) Slog.d(TAG_STATES, "pauseBackStacks: stack=" + stack + " mResumedActivity=" + stack.mResumedActivity); someActivityPaused |= stack.startPausingLocked(userLeaving, false, resuming, dontWait); } } } return someActivityPaused; }

// TODO // 快挂了,回头有时间在补

转载请注明原文地址: https://www.6miu.com/read-1600233.html

最新回复(0)