Reputation: 19
i have a trouble with PopupWindow android default widget. When i touch button to show popup and than press back button on the phone, before popup was shown, i have force close message, the error is next:
10-14 16:51:53.389: ERROR/AndroidRuntime(3766): FATAL EXCEPTION: main
java.lang.NullPointerException
at android.widget.PopupWindow$PopupViewContainer.dispatchKeyEvent(PopupWindow.java:1342)
at android.view.ViewRoot.deliverKeyEventToViewHierarchy(ViewRoot.java:2471)
at android.view.ViewRoot.deliverKeyEvent(ViewRoot.java:2431)
at android.view.ViewRoot.handleMessage(ViewRoot.java:1741)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
So, after some tests i see, this bug is reproduces on android < 2.3 versions (2.1 , 2.2) also i'm dig deep into the sources at grepcode, there is method:
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
if (event.getAction() == KeyEvent.ACTION_DOWN
&& event.getRepeatCount() == 0) {
getKeyDispatcherState().startTracking(event, this);
return true;
} else if (event.getAction() == KeyEvent.ACTION_UP
&& getKeyDispatcherState().isTracking(event) && !event.isCanceled()) {
dismiss();
return true;
}
return super.dispatchKeyEvent(event);
} else {
return super.dispatchKeyEvent(event);
}
}
...
public KeyEvent.DispatcherState getKeyDispatcherState() {
return mAttachInfo != null ? mAttachInfo.mKeyDispatchState : null;
}
and method getKeyDispatcherState() return null
Does anyone have solved this problem?
Upvotes: 1
Views: 2153
Reputation: 3519
This is a bug on android I believe.
Posted here: http://hg.mozilla.org/releases/mozilla-aurora/rev/caca38771162
Upvotes: 0
Reputation: 11
The focus of this issue is you give focus to the Popupwindow before it is shown, so the dispatchevent will receive the back-key before your activity, but now your Popupwindow is not shown. You can test by not giving the focus to the Popupwindow and you will understand what I mean.
Upvotes: 1