Android面试题总结|基本知识梳理---持续更新
梳理背景
最近准备换工作了,这两天面试了几家真的很受打击。就像一位大佬说的,不是技术要求高了,而是企业招聘更理性了。好好反思自己处理平时到处百度copy,paste,还有什么提升呢。早已不是了解四大组件就能收到各种offer的年代了。
决定好好的梳理一下知识点为了面试也为了督促自己学习。
写一篇文章,像种一颗种子。能让它长大成参天大树的,只有自己。以后要常常总结,不论是简单的还是复杂的。提醒自己应该务实一些,摸鱼只会让自己深陷泥潭。
以后应该会保持高频率的更新和学习。
2018/10/28 — 生命周期知识点
生命周期
Activity生命周期
fragment生命周期
activity&fragment生命周期
(activity fragment)
onAttach->onCreate->onCreateView->onCreate ->onActivityCreated->onStart->onStart->onResume->onResume->onPause->onPause->onStop->onStop->onDestroyView->onDestroy->onDetach->onDestroy
onfingChanges对生命周期的影响
AndroidManifest添加android:configChanges=“orientation”
会执行onConfigurationChanged而不会重新开始activity&fragment生命周期
布局相关
LayoutInflater中inflate方法三个参数
public View inflate(@LayoutRes int resource, @Nullable ViewGroup root, boolean attachToRoot)
1 root不为null,attachToRoot为true (即会把resource添加到root中,并会保留layout的布局属性)
2.root不为null,attachToRoot为false(即不会给layout添加父元素,但会保留layout的布局属性)
3.当root为null时,不论attachToRoot为true还是为false,效果都是一样的。(即不会给layout添加父元素,也不会拥有根部局的布局属性)
inflate方法两个参数
public View inflate(XmlPullParser parser, @Nullable ViewGroup root) {
return inflate(parser, root, root != null);
}
1.root为空时,(即不会给layout添加父元素,也不会拥有根部局的布局属性)
2.root不为空,(即会把resource添加到root中,并会保留layout的布局属性)
popwindow
解决PopupWindow无法覆盖状态栏(sdk > 21)
方法1:(已知bug软键盘会覆盖布局不会自动上移)
popupWindow.setClippingEnabled(false);
方法2:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
try {
Field mLayoutInScreen = PopupWindow.class.getDeclaredField("mLayoutInScreen");
mLayoutInScreen.setAccessible(true);
mLayoutInScreen.set(popupWindow, true);
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
gradle
找不到:import org.reactivestreams.Publisher;
解决办法:gradle版本从3.4.0退回到3.3.1
修改文件:D:\android\work\DoraemonKit-master\QuickMvvM\build.gradle
classpath ‘com.android.tools.build:gradle:3.3.1’
//classpath ‘com.android.tools.build:gradle:3.4.0’
修改文件:D:\android\work\DoraemonKit-master\QuickMvvM\gradle\wrapper\gradle-wrapper.properties
distributionUrl=https://services.gradle.org/distributions/gradle-4.10.1-all.zip
#distributionUrl=https://services.gradle.org/distributions/gradle-5.1.1-all.zip