無論是任何類型的開發(fā)工作沟堡,出錯都在所難免,而錯誤報告對于找出和解決問題至關(guān)重要
https://source.android.com/setup/read-bug-reports?hl=zh-cn
本文記錄Android應(yīng)用調(diào)試問題柏锄,并將持續(xù)不斷更新
1趾娃、Caused by: java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter savedInstanceState
【解決方法】Fragment中的override fun onCreatePreferences方法參數(shù)savedInstanceState加上可空標(biāo)識耕突,如:savedInstanceState: Bundle?
2炕泳、java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter convertView
【解決方法】參數(shù)convertView指定為非空的浙芙,實(shí)際為空了,將contentView:View改為contentView: View?
3、注冊ContentObserver,更新完數(shù)據(jù)庫放妈,執(zhí)行notifyChange延遲問題
【原因】在優(yōu)化MediaProvider的操作時托启,Google注意到許多后臺應(yīng)用注冊ContentObservers拐迁,當(dāng)發(fā)生改變進(jìn)行通知時疗绣,會影響相機(jī)應(yīng)用程序做持久重度操作例如:a burst capture线召。為了達(dá)到平衡割卖,將延遲邏輯移入到了ContentService鹏溯,僅將即時通知發(fā)送到前臺應(yīng)用肺孵,后臺應(yīng)用會延時10秒收到有關(guān)更改的消息。詳見google的修改記錄:https://android.googlesource.com/platform/frameworks/base/+/462062c91cc2bad6d289ded27d3d5d7b53e224fb%5E%21/#F0
【解決方法】
通過下面這筆可知紫新,https://android.googlesource.com/platform/frameworks/base/+/9d475e958df9ea0f558458de6629733d5b1fd3e1%5E%21/#F1,可以知道Google后續(xù)增加了flag解決此問題
final boolean noDelay = (key.flags & ContentResolver.NOTIFY_NO_DELAY) != 0;
只要noDelay返回true凤类,則不會延遲通知,而flags是notifyChange時透傳過來的现诀,此處更改flag為:
int flag = (syncToNetwork ? NOTIFY_SYNC_TO_NETWORK : 0) | ContentResolver.NOTIFY_NO_DELAY
即可讓通知不延遲
4夷磕、ActivityManager調(diào)用getRunningAppProcesses()無法獲取到當(dāng)前運(yùn)行App List
【原因】調(diào)用上述接口時,需要申請android.Manifest.permission.REAL_GET_TASKS 權(quán)限
boolean isGetTasksAllowed(String caller, int callingPid, int callingUid) {
if (getRecentTasks().isCallerRecents(callingUid)) {
// Always allow the recents component to get tasks
return true;
}
boolean allowed = checkGetTasksPermission(android.Manifest.permission.REAL_GET_TASKS,
callingPid, callingUid) == PackageManager.PERMISSION_GRANTED;
5仔沿、View 的 按鍵響應(yīng)延遲100ms坐桩,setPressed回調(diào)延遲100ms執(zhí)行的原因
【原因】View的onTouchEvent 可知,響應(yīng)Down事件時封锉,會取判斷當(dāng)前view的父view是否可滑動绵跷,如果可滑動膘螟,延遲100ms處理setPressed狀態(tài)
// Walk up the hierarchy to determine if we're inside a scrolling container.
boolean isInScrollingContainer = isInScrollingContainer();
// For views inside a scrolling container, delay the pressed feedback for
// a short period in case this is a scroll.
//判斷當(dāng)前父view是否可滑動
if (isInScrollingContainer) {
mPrivateFlags |= PFLAG_PREPRESSED;
if (mPendingCheckForTap == null) {
mPendingCheckForTap = new CheckForTap();
}
mPendingCheckForTap.x = event.getX();
mPendingCheckForTap.y = event.getY();
postDelayed(mPendingCheckForTap, ViewConfiguration.getTapTimeout());
} else {
// Not inside a scrolling container, so show the feedback right away
setPressed(true, x, y);
checkForLongClick(
ViewConfiguration.getLongPressTimeout(),
x,
y,
TOUCH_GESTURE_CLASSIFIED__CLASSIFICATION__LONG_PRESS);
}
break;
6、Long monitor contention with owner
7碾局、應(yīng)用本地實(shí)現(xiàn)的接口不會回調(diào)
【原因】系統(tǒng)與應(yīng)用解耦荆残,為了兼容Q與R版本,加了add-on-adapter層sdk適配净当,適配時接口未實(shí)現(xiàn)框架的接口内斯,故應(yīng)用實(shí)現(xiàn)的接口類型是add-on-adapter中的,framework中執(zhí)行的代碼接口類型是add-on中的蚯瞧,類型不一致嘿期,判斷有問題導(dǎo)致不會回調(diào)。
8埋合、Binary XML file line #38 in com.android.contacts:layout/item_group_membership
布局文件未設(shè)置為public