android开机动画到桌面黑屏解决办法
开机过程,从android动画到桌面显示的时候会有黑屏现象,网上也有很多解决办法,这里介绍的方法用的是通过判断一个标志位,当标志位还没有为1时,android动画BootAnimation::checkExit()不能退出,直接返回;当真正进入桌面后,把标志位设为1,BootAnimation::checkExit()才能退出,真正完成开机动画的播放
播放动画结束标志
frameworks\base\cmds\bootanimation\BootAnimation.cpp
static const char EXIT_ANIM_NAME[] = "persist.bootanim.exit";//自定义属性
void BootAnimation::checkExit() {
// Allow surface flinger to gracefully request shutdown
char value[PROPERTY_VALUE_MAX];
char jvalue[PROPERTY_VALUE_MAX];
property_get(EXIT_PROP_NAME, value, "0");
property_get(EXIT_ANIM_NAME, jvalue, "0");
int exitnow = atoi(value);
int jexitnow = atoi(jvalue);
if (exitnow) {
if(jexitnow == 0) {
retrun;
}
requestExit();
mCallbacks->shutdown();
}
}
frameworks\base\services\core\java\com\android\server\am\ActivityRecord.java
private boolean checkBootAnimationCompleteLocked() {
//if (SystemService.isRunning(BOOT_ANIMATION_SERVICE)) {
if(!"1".equals(SystemProperties.get("service.bootanim.exit", "0"))){//判断标志位是否已经为1
mH.removeMessages(H.CHECK_IF_BOOT_ANIMATION_FINISHED);
mH.sendEmptyMessageDelayed(H.CHECK_IF_BOOT_ANIMATION_FINISHED,
BOOT_ANIMATION_POLL_INTERVAL);
if (DEBUG_BOOT) Slog.i(TAG_WM, "checkBootAnimationComplete: Waiting for anim complete");
return false;
}
if (DEBUG_BOOT) Slog.i(TAG_WM, "checkBootAnimationComplete: Animation complete!");
return true;
}
frameworks\base\services\core\java\com\android\server\wm\WindowManagerService.java
private void reportLaunchTimeLocked(final long curTime) {
final ActivityStack stack = getStack();
if (stack == null) {
return;
}
final long thisTime = curTime - displayStartTime;
final long totalTime = stack.mLaunchStartTime != 0
? (curTime - stack.mLaunchStartTime) : thisTime;
if(shortComponentName!=null&&shortComponentName.contains("yourlauncher")){//判断是否已经启动你launcher
SystemProperties.set("persist.bootanim.exit", "1");//设置启动完成标志
}
。。。。。。
另外一种解决办法,参考https://blog.csdn.net/DKBDKBDKB/article/details/101284914
android7.0之后,引入了directboot模式,系统启动后,开机动画走完,是先走到了Settings下一个FallbackHome.java 的activity,这个里边再去引出真正的Launcher,而这个activity是没有任何布局文件的,所以该过程就黑了,怎么体现衔接性呢,由于我们的设备开机动画是静态的一张图片,因此想到了在进入这个activity之后,将背景设置为开机动画图片,从而实现了动画到launcher的无缝连接!!!
具体改动如下:
diff --git a/src/com/android/settings/FallbackHome.java b/src/com/android/settings/FallbackHome.java
index 5f7b639..0686ffa 100644
--- a/src/com/android/settings/FallbackHome.java
+++ b/src/com/android/settings/FallbackHome.java
@@ -64,6 +64,9 @@ public class FallbackHome extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+ //getWindow().getDecorView().setBackgroundColor(Color.WHITE);
+ Log.e(TAG, "========= FallbackHome start display picture ==========");
+ getWindow().setBackgroundDrawableResource(R.drawable.start);
// Set ourselves totally black before the device is provisioned so that
// we don't flash the wallpaper before SUW
mProvisioned = Settings.Global.getInt(getContentResolver(),
@@ -125,6 +128,8 @@ public class FallbackHome extends Activity {
Log.d(TAG, "User unlocked and real home found; let's go!");
getSystemService(PowerManager.class).userActivity(
SystemClock.uptimeMillis(), false);
+ //this.getWindow().getDecorView().setBackgroundColor(Color.WHITE);
+ Log.e(TAG, "========= FallbackHome stop display picture ==========");
finish();
}
}
另外把start.png(开机图片)放至drawable目录。
本文地址:https://blog.csdn.net/andylao62/article/details/107150917
下一篇: ADB入门