最后
在这里小编整理了一份Android大厂常见面试题,和一些Android架构视频解析,都已整理成文档,全部都已打包好了,希望能够对大家有所帮助,在面试中能顺利通过。
喜欢本文的话,不妨顺手给我点个小赞、评论区留言或者转发支持一下呗
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
flutterView.attachToFlutterEngine(flutterEngine);
return flutterSplashView;
}
这里我们可以大致了解到,创建了一个FlutterSurfaceView 它继承自surfaceView(我们的flutter页面也是渲染在这个surface上的)。之后我们用它初始化一个FlutterView,
FlutterView继承自 FrameLayout
随后我们再创建一个FlutterSplashView (继承FrameLayout)并调用displayFlutterViewWithSplash()方法。
public void displayFlutterViewWithSplash(
@NonNull FlutterView flutterView, @Nullable SplashScreen splashScreen) {
// If we were displaying a previous FlutterView, remove it.
if (this.flutterView != null) {
this.flutterView.removeOnFirstFrameRenderedListener(flutterUiDisplayListener);
removeView(this.flutterView);
}
// If we were displaying a previous splash screen View, remove it.
if (splashScreenView != null) {
removeView(splashScreenView);
}
// Display the new FlutterView.
this.flutterView = flutterView;
///添加flutterView
addView(flutterView);
this.splashScreen = splashScreen;
// Display the new splash screen, if needed.
if (splashScreen != null) {
if (isSplashScreenNeededNow()) {
Log.v(TAG, “Showing splash screen UI.”);
// This is the typical case. A FlutterEngine is attached to the FlutterView and we’re
// waiting for the first frame to render. Show a splash UI until that happens.
splashScreenView = splashScreen.createSplashView(getContext(), splashScreenState);
///添加 splashScreenView
addView(this.splashScreenView);
flutterView.addOnFirstFrameRenderedListener(flutterUiDisplayListener);
} else if (isSplashScreenTransitionNeededNow()) {
Log.v(
TAG,
“Showing an immediate splash transition to Flutter due to previously interrupted transition.”);
splashScreenView = splashScreen.createSplashView(getContext(), splashScreenState);
addView(splashScreenView);
transitionToFlutter();
} else if (!flutterView.isAttachedToFlutterEngine()) {
Log.v(
TAG,
“FlutterView is not yet attached to a FlutterEngine. Showing nothing until a FlutterEngine is attached.”);
flutterView.addFlutterEngineAttachmentListener(flutterEngineAttachmentListener);
}
}
}
这个方法对flutterView进行了保存(不用管这个),随后我们保存了一个 接口的实现类——splashScreen,这个实现类则是由FlutterActivity实现的(MainActivity)来提供的:
///host 是个接口,由FlutterActivity实现
回顾上面:flutterSplashView.displayFlutterViewWithSplash(flutterView, host.provideSplashScreen());
public SplashScreen provideSplashScreen() {
Drawable manifestSplashDrawable = getSplashScreenFromManifest();
if (manifestSplashDrawable != null) {
///DrawableSplashScreen 实现了 splashScreen的接口
return new DrawableSplashScreen(manifestSplashDrawable);
} else {
return null;
}
}
通过getSplashScreenFromManifest 初始化了一个drawable,我们看一下它内部:
@Nullable
@SuppressWarnings(“deprecation”)
private Drawable getSplashScreenFromManifest() {
try {
ActivityInfo activityInfo =
getPackageManager().getActivityInfo(getComponentName(), PackageManager.GET_META_DATA);
Bundle metadata = activityInfo.metaData;
///这里就是我们在 AndroidManifest.xml中设置启动页了
///SPLASH_SCREEN_META_DATA_KEY 的值 见下方
int splashScreenId = metadata != null ? metadata.getInt(SPLASH_SCREEN_META_DATA_KEY) : 0;
return splashScreenId != 0
? Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP
? getResources().getDrawable(splashScreenId, getTheme())
getResources().getDrawable(splashScreenId)
null;
} catch (PackageManager.NameNotFoundException e) {
// This is never expected to happen.
return null;
}
}
static final String SPLASH_SCREEN_META_DATA_KEY =
“io.flutter.embedding.android.SplashScreenDrawable”;
可以看到,通过上面的方法,我们以在AndroidManifest.xml设置的启动资源 初始化了一个drawable,进而初始化了DrawableSplashScreen 并返回。
我们回到displayFlutterViewWithSplash 继续向下看,
///通过我们之前的drawable 生成一个 view
splashScreenView = splashScreen.createSplashView(getContext(), splashScreenState);
///添加 splashScreenView
addView(this.splashScreenView);
到了这里,整个闪屏页的流程就跑完了。
回头看去,可以发现在闪屏页的显示到引擎的启动及flutter 页面的显示会有一个很长的过程,而直到flutter 页面的显示,这个闪屏页才会被移除掉。
那么如何优化呢? 以下是我的方案。
启动页优化方案
=====================================================================
因为flutter与原生处于两个不同的surface,所以我们可以考虑利用原生的surface来显示这个启动页,同时为了避免拖慢flutter的启动,我们可以在子线程来做这个事情。ww
案例中我们显示一个svga动画
插件使用:‘com.github.yyued:SVGAPlayer-Android:2.5.12’
实现
直接开工,我们写个方法initSplashPage() :
public void initSplashPage(){
Executors.newSingleThreadExecutor()
.execute(new Runnable() {
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数初中级安卓工程师,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
安卓工程师,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!**
[外链图片转存中…(img-JVL9yTxf-1715666240662)]
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!