在android6.0 Dialer主界面添加了一个事件监听。就是OnkeyDown方法,当点击手机上的menu键时弹出搜索框的popupmenu。于是添加了以下方法:
public  boolean onKeyDown(int keyCode, KeyEvent keyEvent) {

        if (keyCode == KeyEvent.KEYCODE_MENU) {
Log.d(TAG, "DialtactsActivity popupMenu menuKeypressed");
 if(mIsDialpadShown){
mDialpadFragment.onMenupressed();
}else if(!isInSearchUi()){
mOverflowMenu.show();
Log.d(TAG, "DialtactsActivity popupMenu is show");
}
return true;
        }
if(keyCode == KeyEvent.KEYCODE_BACK){
onBackPressed();
Log.d(TAG, "DialtactsActivity popupMenu -- onback is called");

        return false;
    }
结果神奇的一幕出现了,偶尔会出现弹出一半立即消失的情况。。
log文件如下:
D DialtactsActivity: DialtactsActivity popupMenu menuKeypressed
D DialtactsActivity: DialtactsActivity popupMenu show() is called
W art     : Long monitor contention event with owner method=android.content.pm.ParceledListSlice com.android.server.pm.PackageManagerService.getInstalledPackages(int, int) from PackageManagerService.java:5619 waiters=0 for 339ms
D AppLockStrategy: checkAppLockStatus packageName=com.android.dialer activity=com.android.dialer.DialtactsActivity mustShow=false
D AppLockStrategy: packageName = mLastResumedPkg=com.android.dialer
D AbsListView: checkAbsListViewlLogProperty get invalid command
D ListView: measureHeightOfChildren adapter = com.android.internal.view.menu.MenuPopupHelper$MenuAdapter@5313136, startPosition = 0, endPosition = 3, maxHeight = 1120, this = android.widget.ListPopupWindow$DropDownListView{1f96f5a VFED.VC.. ......I. 0,0-0,0}
D ViewGroup: setClipChildren to FALSE!! this = android.widget.PopupWindow$PopupDecorView{cf68fb2 V.E...... ......I. 0,0-0,0}
D WifiNumberDataBase: fetchData packagename = [com.android.dialer]
D WifiNumberDataBase:  fetchData ==============0
D PopupWindow: invokePopup: mDecorView = android.widget.PopupWindow$PopupDecorView{cf68fb2 V.E...... ......I. 0,0-0,0}, WindowManager.LayoutParams = WM.LayoutParams{(312,64)(392x384) gr=#10000033 sim=#1 ty=1002 fl=#40860200 fmt=-3 surfaceInsets=Rect(64, 64 - 64, 64) (manual)}
D WindowClient: Add to mViews: android.widget.PopupWindow$PopupDecorView{cf68fb2 V.E...... ......I. 0,0-0,0}, this = android.view.WindowManagerGlobal@695680b
D OpenGLRenderer: CanvasContext() 0x7f87982000
D ViewRootImpl: hardware acceleration is enabled, this = ViewRoot{a6f9b03 PopupWindow:1ec0114,ident = 10}
V DisplayEventReceiver: call nativeScheduleVsync mReceiverPtr = 547787998336
D SurfaceFlinger: requestNextVsync(3892)
D PhoneStatusBar: setSystemUiVisibility vis=8000 mask=ffffffff oldVal=8600 newVal=8000 diff=600
D PhoneStatusBar: hiding the MENU button
D DialtactsActivity: DialtactsActivity popupMenu is show
正常的log文件如下:D DialtactsActivity: DialtactsActivity popupMenu menuKeypressed
D DialtactsActivity: DialtactsActivity popupMenu show() is called
D AbsListView: checkAbsListViewlLogProperty get invalid command
D ListView: measureHeightOfChildren adapter = com.android.internal.view.menu.MenuPopupHelper$MenuAdapter@5313136, startPosition = 0, endPosition = 3, maxHeight = 1120, this = android.widget.ListPopupWindow$DropDownListView{ed1f2a VFED.VC.. ......I. 0,0-0,0}
D ViewGroup: setClipChildren to FALSE!! this = android.widget.PopupWindow$PopupDecorView{7166982 V.E...... ......I. 0,0-0,0}
D PopupWindow: invokePopup: mDecorView = android.widget.PopupWindow$PopupDecorView{7166982 V.E...... ......I. 0,0-0,0}, WindowManager.LayoutParams = WM.LayoutParams{(312,64)(392x384) gr=#10000033 sim=#1 ty=1002 fl=#40860200 fmt=-3 surfaceInsets=Rect(64, 64 - 64, 64) (manual)}
D WindowClient: Add to mViews: android.widget.PopupWindow$PopupDecorView{7166982 V.E...... ......I. 0,0-0,0}, this = android.view.WindowManagerGlobal@695680b
D OpenGLRenderer: CanvasContext() 0x7f877ab000
D ViewRootImpl: hardware acceleration is enabled, this = ViewRoot{53cb893 PopupWindow:471b264,ident = 2}
V DisplayEventReceiver: call nativeScheduleVsync mReceiverPtr = 547787998336
D SurfaceFlinger: requestNextVsync(3892)
D SurfaceFlinger: postEvent(3892, v/c=2265)
D PhoneStatusBar: setSystemUiVisibility vis=8000 mask=ffffffff oldVal=8600 newVal=8000 diff=600
D PhoneStatusBar: hiding the MENU button
D DialtactsActivity: DialtactsActivity popupMenu is show注意到出现异常的SurfaceFlinger: postEvent(3892, v/c=2265)并没有出现,所以原因是不是在这里呢?
我就给方法前加上了synchronized,然而并不能解决问题。。求大神解答