Read, think and write.
Notes
Android graphics tips
如果给Paint同时设置了shader和color,会优先使用shader的颜色,例如drawText时,文字颜色是shader的颜色,而非color所指定的颜色。
虽然官方文档表明开启硬件加速时,只要ComposeShader里包含的shader是不同的类型且不是ComposeShader,那么在api 28以下也可以使用ComposeShader,但实际测试结果是只有关闭硬件加速ComposeShader才起作用。
如果给Paint设置了PathEffect,path的FillType是EVEN_ODD时会失效。
Notes
Android command line
Show current tasks
adb shell dumpsys activity activites
Show screen infos
adb shell dumpsys window
Show gfxinfo
adb shell dumpsys gfxinfo <PACKAGE_NAME>
Notes
Android tips
如果要在低版本系统上使用高版本系统才加入的类,可以在app中加入同名类,在高版本系统上安装时这个同名类会删除,还是使用系统的类,在低版本系统则使用在app中加入的类。
在不同的PendingIntent的Intent中设置extra,在处理Intent的地方获取的extra始终相同,可以通过设置不同RequestCode来区分不同的PendingIntent。
对于 replace Fragment,通过代码和 layout 文件加入最初的 Fragment 这两种方式之间是有区别的,replace 后最初 Fragment 的 onDestroyView 方法都会被调用,但再回退时,通过代码方式加入的最初 Fragment 会重新显示,其 onCreateView 方法会被调用,而 layout 文件方式不会重新显示。
在xml中加入fragment时键盘会自动弹出,通过代码加入时不会。
AsyncTask在3.0以前是并行执行的,3.0及以后顺序执行的,AsyncTask是通过静态的Handler成员变量将结果post到主线程中执行的,所以要确保加载AsyncTask类是在主线程中执行的,在4.1及以后系统已经确保的这一点。
如果自己decode ninepatch图片,要先compile ninepatch图片。
android ListView Adapter’s getView method sometimes provide a wrong type convertView. stackoverflow
市场解锁、gaeproxy等软件会修改运营商信息。
cookie里包含有特殊字符会导致请求失败。
Bitmap.createBitmap在低内存时在有些手机上可能返回null,而不是抛OutofMemoryError。
对于apk压缩包的操作应使用android自带的aapt,避免直接使用zip,直接使用zip会将apk里面的raw资源压缩,导致有些rom下读取raw文件失败。
如果不给WebView设置WebViewClient,在有些手机上会自动跳到系统浏览器。
在Androd 7.0上如果使用FLAG_ACTIVITY_REORDER_TO_FRONT来启动activity,快速连续点击不断启动activity时,可能会回到桌面。
在MIUI10上通过Fragment的startActivity方法来启动activity,通过theme中windowAnimationStyle设置的进入动画会失效。
Notes
Android studio tips
Share module between projects Add this to settings.gradle file at the project root:
include ':libraryName' project(':libraryName').projectDir=new File('/path/to/library') where the path you specify in the second line is the path to the directory containing the library’s build.gradle file. The path can be relative or absolute.
Avoid so file can not find problem If library’s jniLibs contians armeabi-v7a folder, but main module’s jniLibs contains not, the app will crash because of so file could not found.