1.GLSurfaceView把上层的View遮盖
在使用GLSurfaceView开发的时候,会调到到setZOrderOnTop(boolean onTop)这个方法,而这个方法大概的意思是将GLSurfaceView放置到window界面的最上层,所以GLSurfaceView上面是不会显示其他View的。下面这个段是官方对这个方法的介绍。
Control whether the surface view's surface is placed on top of its window. Normally it is placed behind the window, to allow it to (for the most part) appear to composite with the views in the hierarchy. By setting this, you cause it to be placed above the window. This means that none of the contents of the window this SurfaceView is in will be visible on top of its surface.
Note that this must be set before the surface view's containing window is attached to the window manager. If you target `[Build.VERSION_CODES#R](https://developer.android.google.cn/reference/android/os/Build.VERSION_CODES#R)` the Z ordering can be changed dynamically if the backing surface is created, otherwise it would be applied at surface construction time.
Calling this overrides any previous call to [setZOrderMediaOverlay(boolean)](https://developer.android.google.cn/reference/android/view/SurfaceView#setZOrderMediaOverlay(boolean)).
在这段官方介绍的最后提到了setZOrderMediaOverlay(boolean isMediaOverlay)这个方法,下面是setZOrderMediaOverlay的官方介绍,这段介绍不太好理解,根据我自身的使用和理解,这段介绍的意思是调用setZOrderMediaOverlay方法后,GLSurfaceView依然会显示在最上面,只是会在对应的位置开一个口显示需要置顶的View。
Control whether the surface view's surface is placed on top of another regular surface view in the window (but still behind the window itself). This is typically used to place overlays on top of an underlying media surface view.
Note that this must be set before the surface view's containing window is attached to the window manager.
Calling this overrides any previous call to `[setZOrderOnTop(boolean)](https://developer.android.google.cn/reference/android/view/SurfaceView#setZOrderOnTop(boolean))`.
2.使用Arrays将数组转集合,再进行添加或移除的时候报UnsupportedOperationException错误
在Arrays类里面有一个自定义的ArrayList类,而这个类并没有实现add和remove方法,在AbstractList类中,这个两个方法直接抛出UnsupportedOperationException错误,所以在使用Arrays的asList方法的时候要注意得到的ArrayList集合并不是我们平时使用java.util.ArrayList类得到的集合
3.Type BuildConfig is defined multiple times
在多模块开发的时候,如果AndroidManifest.xml文件中的package相同则会导致出现这个问题。
4.当背景资源设置成select的时候,当view的enable设置成false的时候没有切换到对应enable=false的资源
错误的顺序:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/shape_func1_radius_60" android:state_pressed="false" />
<item android:drawable="@drawable/shape_func14_radius_60" android:state_pressed="true" />
<item android:drawable="@drawable/shape_func1_radius_60" android:state_enabled="true" />
<item android:drawable="@drawable/shape_func14_radius_60" android:state_enabled="false" />
</selector>
根据你提供的selector资源,当View处于disabled状态时,它的背景色应该显示为@drawable/shape_func14_radius_60对应的颜色。但是,你发现当View的android:enabled属性设置为false时,它的背景色并没有显示为@drawable/shape_func14_radius_60对应的颜色。
这种情况可能是由于selector资源中的item顺序导致的。在selector资源中,item的顺序很重要,因为它决定了哪个item会被优先匹配。在你的selector资源中,第三个item和第四个item都定义了android:state_enabled属性,但是它们的顺序错误。
正确的item顺序应该是这样的:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/shape_func14_radius_60" android:state_pressed="true" />
<item android:drawable="@drawable/shape_func14_radius_60" android:state_enabled="false" />
<item android:drawable="@drawable/shape_func1_radius_60" android:state_enabled="true" />
<item android:drawable="@drawable/shape_func1_radius_60" />
</selector>
在上面的selector资源中,第一个item定义了View处于pressed状态时的背景色,第二个item定义了View处于disabled状态时的背景色,第三个item定义了View处于enabled状态时的背景色,第四个item定义了View处于默认状态时的背景色。
当View的android:enabled属性设置为false时,selector资源会优先匹配第二个item,因此View的背景色会显示为@drawable/shape_func14_radius_60对应的颜色。
需要注意的是,在selector资源中,如果多个item的state属性都匹配当前的状态,那么selector资源会优先匹配第一个满足条件的item。因此,在定义selector资源时,应该尽可能地避免定义冲突的item。
5.Kotlin和Java混合使用出现空指针异常
当使用Kotlin实现Java的接口时候需要注意接口方法的参数是否能为空的问题
public interface ITestListener {
void onTest(String data);
}
...
ITestListener listener = ...;
listener.onTest(null);
...
Java在定义接口的时候是可以不用设置参数是否能为空,但是在实际调用的时候是可以传空参数进去的。 而Kotlin在实现这个接口的时候,参数可空是需要加上?代表参数可空,如果在实现这个接口的时候没有加上?,而调用方传参的时候使用null,这个时候就会出现空指针异常。
//这个是错误的演示
val listener = object:ITestListener {
fun onTest(data: String) {
//data参数没有设置成可空,那么如果调用方传参的时候设置null,这里就会出现空指针异常
}
}
所以在做Kotlin和Java混合开发的时候,Kotlin在实现Java接口的时候尽量将Java中非基础类型的参数设置成可空。
//这个是正确的演示
val listener = object:ITestListener {
fun onTest(data: String?) {
//data参数设置成可空,那么调用方传来null也不会出现空指针异常
}
}
6.so 崩溃堆栈解析
1.需要将崩溃的堆栈信息从*******开始保存 2.执行./ndk-stack -sym <so库的目录> -dump <保存崩溃信息的文件> 3.执行用的 ndk-stack 要使用编译 so 库对应的 ndk 版本,路径一般位于Android sdk 的 NDK 目录中
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Build fingerprint: ''
Revision: '0'
ABI: 'arm64'
Timestamp:
Process uptime: 55s
Cmdline:
pid: 25202, tid: 27734, name:
uid: 10390
tagged_addr_ctrl: 0000000000000001 (PR_TAGGED_ADDR_ENABLE)
pac_enabled_keys: 000000000000000f (PR_PAC_APIAKEY, PR_PAC_APIBKEY, PR_PAC_APDAKEY, PR_PAC_APDBKEY)
signal 6 (SIGABRT), code -1 (SI_QUEUE), fault addr --------
Abort message: 'Scudo ERROR: invalid chunk state when deallocating address 0x20000746d42d350'
x0 0000000000000000 x1 0000000000006c56 x2 0000000000000006 x3 00000072860fd920
x4 64736073721f6a6d x5 64736073721f6a6d x6 64736073721f6a6d x7 7f7f7f7f7f7f7f7f
x8 00000000000000f0 x9 00000075dd68f920 x10 0000000000000001 x11 00000075dd71b4c0
x12 00000075e31ed020 x13 000000007fffffff x14 0000000002c0a9ea x15 00000496365c7647
x16 00000075dd78aa60 x17 00000075dd763dd0 x18 0000006efcfb4000 x19 0000000000006272
x20 0000000000006c56 x21 00000000ffffffff x22 0000000000000000 x23 0000000000006272
x24 00000072860fdcb0 x25 00000072860fdcb0 x26 00000072860fdff8 x27 00000075e1e4b000
x28 0000000000000000 x29 00000072860fd9a0
lr 00000075dd70b898 sp 00000072860fd900 pc 00000075dd70b8c4 pst 0000000000001000
13 total frames
backtrace:
#00 pc 00000000000a58c4 /apex/com.android.runtime/lib64/bionic/libc.so (abort+164) (BuildId: 35647bdbfd4abaae505972042de0d304)
#01 pc 0000000000090618 /apex/com.android.runtime/lib64/bionic/libc.so (scudo::die()+8) (BuildId: 35647bdbfd4abaae505972042de0d304)
#02 pc 0000000000091240 /apex/com.android.runtime/lib64/bionic/libc.so (scudo::ScopedErrorReport::~ScopedErrorReport()+32) (BuildId: 35647bdbfd4abaae505972042de0d304)
#03 pc 0000000000091764 /apex/com.android.runtime/lib64/bionic/libc.so (scudo::reportInvalidChunkState(scudo::AllocatorAction, void*)+116) (BuildId: 35647bdbfd4abaae505972042de0d304)
#04 pc 000000000009351c /apex/com.android.runtime/lib64/bionic/libc.so (scudo::Allocator<scudo::AndroidConfig, &(scudo_malloc_postinit)>::deallocate(void*, scudo::Chunk::Origin, unsigned long, unsigned long)+332) (BuildId: 35647bdbfd4abaae505972042de0d304)