一个EditText引发的PopupWindow崩溃

// android.view.WindowManager$BadTokenException: Unable to add window – token null is not valid; is your activity running?
// at android.view.ViewRootImpl.setView(ViewRootImpl.java:858)
// at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:356)
// at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:94)
// at android.widget.PopupWindow.invokePopup(PopupWindow.java:1434)
// at com.miui.internal.variable.v21.Android_Widget_PopupWindow_class.callOriginalInvokePopup(SourceFile:68)
// at com.miui.internal.variable.v23.Android_Widget_PopupWindow_class.callOriginalInvokePopup(SourceFile:64)
// at com.miui.internal.variable.v21.Android_Widget_PopupWindow_class.handleInvokePopup(SourceFile:63)
// at com.miui.internal.variable.v23.Android_Widget_PopupWindow_class.handleInvokePopup(SourceFile:37)
// at android.widget.PopupWindow.showAtLocation(PopupWindow.java:1203)
// at android.widget.PopupWindow.showAtLocation(PopupWindow.java:1170)
// at android.widget.Editor$AnimatePopupWindow.showAtLocation(Editor.java:3620)
// at android.widget.Editor$ActionPinnedPopupWindow.updatePosition(Editor.java:3236)
// at android.widget.Editor$ActionPopupWindow.updatePosition(Editor.java:4713)
// at android.widget.Editor$PinnedPopupWindow.show(Editor.java:3502)
// at android.widget.Editor$ActionPinnedPopupWindow.show(Editor.java:3361)
// at android.widget.Editor$ActionPopupWindow.access$5001(Editor.java:4141)
// at android.widget.Editor$ActionPopupWindow$3.onPostExecute(Editor.java:4473)
// at com.android.internal.phrase.QueryPhraseTask.onPostExecute(QueryPhraseTask.java:39)
// at com.android.internal.phrase.QueryPhraseTask.onPostExecute(QueryPhraseTask.java:15)
// at android.os.AsyncTask.finish(AsyncTask.java:695)
// at android.os.AsyncTask.access$600(AsyncTask.java:180)
// at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:712)
// at android.os.Handler.dispatchMessage(Handler.java:106)
// at android.os.Looper.loop(Looper.java:201)
// at android.app.ActivityThread.main(ActivityThread.java:6820)
// at java.lang.reflect.Method.invoke(Native Method)
// at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
// at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:922)
//

看日志最后确定是EditText的窗口在消失后,弹出了“复制粘贴”的popwindow

看源码在Activity里面是不会崩溃,由于是直接addWindow,看起来Context不是activity,在ViewRootImpl消失后崩溃了

5310            final boolean shouldNotShowMainPanel = !canCopy && !canCut && !canPaste && !canReplace && !canSelect && !canSelectAll;
5311            if (canPhrase) {//continue to judge the phrase condition
5312                QueryPhraseListener queryPhraseListener = new QueryPhraseListener() {
5313                    @Override
5314                    public void onPostExecute(ArrayList<String> phraseList) {
5315                        final Context context = mPasteTextView == null ? null : mPasteTextView.getContext();
5316                        if (context == null || (context instanceof Activity &&
5317                                (((Activity) context).isFinishing() || ((Activity) context).isDestroyed()))) {
5318                            return;
5319                        }
5320                        mPhrases = phraseList;
5321                        boolean phraseTextViewCanShow = true;
5322                        if (mPhrases.size() == 0) {
5323                            if (isPasswordInputType) {//should not show PhraseTextView if textview is PasswordInputType
5324                                if (shouldNotShowMainPanel) {
5325                                    return;
5326                                }
5327                                phraseTextViewCanShow = false;
5328                            } else {
5329                                mPhraseTextView.setText(android.miui.R.string.add_frequent_phrases);
5330                            }
5331                        } else {
5332                            mPhraseTextView.setText(android.miui.R.string.frequent_phrases);
5333                        }
5334                        mPhraseTextView.setVisibility(phraseTextViewCanShow ? View.VISIBLE : View.GONE);
5335                        setMainPanelChildPadding(phraseTextViewCanShow);
5336                        if (mTextView.getLayout() != null) {
5337                            ActionPopupWindow.super.show();
5338                        }
5339                    }
5340                };
5341                if (mQueryPhraseTask == null || mQueryPhraseTask.getStatus() == AsyncTask.Status.FINISHED) {
5342                    mQueryPhraseTask = new QueryPhraseTask(mTextView.getContext(), queryPhraseListener);
5343                    mQueryPhraseTask.execute();
5344                }
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值