扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
如果是厂商定制系统,可以在设置(厂商可能提供相应的调整界面)中或开发者选项里进行调整
创新互联是一家集网站建设,秀山土家族苗族企业网站建设,秀山土家族苗族品牌网站建设,网站定制,秀山土家族苗族网站建设报价,网络营销,网络优化,秀山土家族苗族网站推广为一体的创新建站企业,帮助传统企业提升企业形象加强企业竞争力。可充分满足这一群体相比中小企业更为丰富、高端、多元的互联网需求。同时我们时刻保持专业、时尚、前沿,时刻以成就客户成长自我,坚持不断学习、思考、沉淀、净化自己,让我们为更多的企业打造出实用型网站。
问题现象:
由于设备有两个Display设备,分为主屏和副屏,正常情况下startActivity如果不指定displayId的话,都会默认显示在主屏上,但是在某些情况下launcher启动的应用Activity会显示到副屏上面去。
根据现象来分析,初步判断问题原因是startActivity的流程出现异常导致的,那么就需要从startActivity流程开始查找原因。
先看framework\base\services\core\java\com\android\server\am\ActivityStarter.java中的:
```
int startActivityLocked(IApplicationThread caller, Intent intent, Intent ephemeralIntent,
...) {
...
mLastStartActivityResult = startActivity(caller, intent, ephemeralIntent, resolvedType,
aInfo, rInfo, voiceSession, voiceInteractor, resultTo, resultWho, requestCode,
callingPid, callingUid, callingPackage, realCallingPid, realCallingUid, startFlags,
options, ignoreTargetSecurity, componentSpecified, mLastStartActivityRecord,
inTask);
...
}
```
一步一步往下查之后看到startActivityUnchecked函数中有对task和stack的变更与displayId相关的操作,重点看这个地方:
// Note: This method should only be called from {@link startActivity}.
private int startActivityUnchecked(final ActivityRecord r, ActivityRecord sourceRecord,
IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor,
int startFlags, boolean doResume, ActivityOptions options, TaskRecord inTask,
ActivityRecord[] outActivity) {
...
// Should this be considered a new task?
int result = START_SUCCESS;
if (mStartActivity.resultTo == null mInTask == null !mAddingToTask
(mLaunchFlags FLAG_ACTIVITY_NEW_TASK) != 0) {
newTask = true;
String packageName= mService.mContext.getPackageName();
if (mPerf != null) {
mStartActivity.perfActivityBoostHandler =
mPerf.perfHint(BoostFramework.VENDOR_HINT_FIRST_LAUNCH_BOOST, packageName, -1, BoostFramework.Launch.BOOST_V1);
}
result = setTaskFromReuseOrCreateNewTask(
taskToAffiliate, preferredLaunchStackId, topStack);
} else if (mSourceRecord != null) {
result = setTaskFromSourceRecord(); //在添加打印后发现出现问题的时候是走的这个函数进行task与stack操作的
} else if (mInTask != null) {
result = setTaskFromInTask();
} else {
// This not being started from an existing activity, and not part of a new task...
// just put it in the top task, though these days this case should never happen.
setTaskToCurrentTopOrCreateNewTask();
}
...
}
那么就看setTaskFromSourceRecord这个函数干了些什么:
private int setTaskFromSourceRecord() {
...
// We only want to allow changing stack in two cases:
// 1. If the target task is not the top one. Otherwise we would move the launching task to
// the other side, rather than show two side by side.
// 2. If activity is not allowed on target display.
final int targetDisplayId = mTargetStack != null ? mTargetStack.mDisplayId
: sourceStack.mDisplayId;
final boolean moveStackAllowed = sourceStack.topTask() != sourceTask
|| !mStartActivity.canBeLaunchedOnDisplay(targetDisplayId);
if (moveStackAllowed) {
mTargetStack = getLaunchStack(mStartActivity, mLaunchFlags, mStartActivity.getTask(),
mOptions);
// If target stack is not found now - we can't just rely on the source stack, as it may
// be not suitable. Let's check other displays.
if (mTargetStack == null targetDisplayId != sourceStack.mDisplayId) {
// Can't use target display, lets find a stack on the source display.
mTargetStack = mService.mStackSupervisor.getValidLaunchStackOnDisplay(
sourceStack.mDisplayId, mStartActivity);
}
if (mTargetStack == null) {
// There are no suitable stacks on the target and source display(s). Look on all
// displays.
mTargetStack = mService.mStackSupervisor.getNextValidLaunchStackLocked(
mStartActivity, -1/* currentFocus */);
}
}
}
根据注释来看,关键就是这个moveStackAllowed了,打印log发现出现问题的时候moveStackAllowed 为true,所以会对mTargetStack 进行重新赋值的操作,在重新赋值操作过程中,由于当前topTask所在的stack是副屏的,所以会进入mService.mStackSupervisor.getNextValidLaunchStackLocked查找非-1的displayId对应的ActivityStack来赋值。
/**
* Get next valid stack for launching provided activity in the system. This will search across
* displays and stacks in last-focused order for a focusable and visible stack, except those
* that are on a currently focused display.
*
* @param r The activity that is being launched.
* @param currentFocus The display that previously had focus and thus needs to be ignored when
* searching for the next candidate.
* @return Next valid {@link ActivityStack}, null if not found.
*/
ActivityStack getNextValidLaunchStackLocked(@NonNull ActivityRecord r, int currentFocus) {
mWindowManager.getDisplaysInFocusOrder(mTmpOrderedDisplayIds);
for (int i = mTmpOrderedDisplayIds.size() - 1; i = 0; --i) {
final int displayId = mTmpOrderedDisplayIds.get(i);
if (displayId == currentFocus) {
continue;
}
final ActivityStack stack = getValidLaunchStackOnDisplay(displayId, r);
if (stack != null) {
return stack;
}
}
return null;
}
从getNextValidLaunchStackLocked内部可以看到按照displayId由小到大的顺序依次添加到mTmpOrderedDisplayIds这个列表中去,然后再由大到小依次遍历mTmpOrderedDisplayIds非-1的displayId对应的ActivityStack,由于设备的主屏和副屏的displayId分别是0、1,所以最先查到的就是displayId为1的ActivityStack,这样activity就会显示到副屏对应的ActivityStack上,从而导致默认启动的activity在副屏上显示的问题。
知道原因就好办了,直接在setTaskFromSourceRecord中添加判断:
if (mTargetStack == null) {
// There are no suitable stacks on the target and source display(s). Look on all
// displays.
ActivityStack topStack = mSupervisor.mFocusedStack;
int currentFocusDisplayId = -1;
//如果topStack对应的displayId不等于startActivity传入的targetDisplayId,那么就在getNextValidLaunchStackLocked中传入topStack.mDisplayId排除掉对应的topStack就行了。
if (topStack != null topStack.mDisplayId != targetDisplayId) {
currentFocusDisplayId = topStack.mDisplayId;
}
mTargetStack = mService.mStackSupervisor.getNextValidLaunchStackLocked(
mStartActivity, currentFocusDisplayId /* currentFocus */);
}
双屏异显为但主板双LVDS点屏功能,异显也可同显,副屏可以显示不同于主屏的内容,可用来向用户展示广告,视频,图片,购物订单等内容。
OBOO数字标牌多媒体信息发布管理软件(OBOO)系统采用B/S架构,拥有完美的跨平台解决方案,其基于网络平台,采用分布式区域管理技术。可以有效整合各种多媒体资源,实现远程制作、发布和管理节目。
同步显示即是将自定义的Presetation关闭掉,Presentation本身就是继承自Dialog,有dismiss方法。
1.修改frameworks\base\core\res\res\values\config.xml中config_lidOpenRotation的值为90。2.修改frameworks\base\services\core\java\com\android\server\wm\WindowManagerService.java中:intmRotation=1;3.修改frameworks\native\services\surfaceflinger\DisplayDevice.cpp里面:setProjection(DisplayState::eOrientation90,mViewport,mFrame);4、交换一下Bootanimation里面的h和w
adb shell am start -n com.android.demo/com.android.demo.MainActivity --display 1
adb shell am start -n com.android.demo/com.android.demo.MainActivity --user 0 --display 1
参数--display指定屏幕, display 0,表示第一块屏幕; display 1,表示第2块屏幕。
参数--user可以启动指定的用户,在多用户下有效,系统默认是--user 0。
Presentation是一个特殊的dialog,它的目的是显示内容到第二屏幕。在Presentation创建的时候关联一个目标设备,确定Presentation要显示在哪个设备上,根据这个设备的信息来配置Presentation的context和resources信息。
获取辅助屏幕有两种方式:MediaRouter或者DisplayManager
备注:
通过Activity的方式显示在副屏上会带来一些问题
1、SoftInputWindow,Toast只显示在主屏
当在副屏的Activity中调用上面控件时,控件会显示到主屏上
以上问题需要修改Framwork适配控件
未完待续……
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流