关于PopupWindow弹出Dialog的问题Activity会被销毁的问题

Charn_Lau 2016-06-08 05:36:31
在一个Activity中,弹出PopupWindow,然后点击PopupWindow的按钮弹出Dialog,然后Activity就被销毁了,没有错误提示。
唯一的提示就是Skipped 63 frames! The application may be doing too much work on its main thread.
但是我这个页面除了弹出PopupWindow和Dialog,并没有耗时操作,请问是怎么回事?有没有什么解决方案?
...全文
373 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
Charn_Lau 2016-06-08
  • 打赏
  • 举报
回复
引用 1 楼 shuijinglingsos 的回复:
贴代码别人才能帮你分析啊,没代码怎么知道哪里有问题?
已经解决了,是我自己犯的低级错误导致的,case忘记break,执行到了finish()了
Charn_Lau 2016-06-08
  • 打赏
  • 举报
回复
引用 1 楼 shuijinglingsos 的回复:
贴代码别人才能帮你分析啊,没代码怎么知道哪里有问题?
代码贴出来了,帮忙看看,谢谢!
Charn_Lau 2016-06-08
  • 打赏
  • 举报
回复
弹出popupwindow
        View contentView = View.inflate(this, R.layout.popup_contact_detail, null);

        mBmivMove = (RelativeLayout) contentView.findViewById(R.id.pop_contact_detail_move);
        pop_contact_detail_share = (RelativeLayout) contentView.findViewById(R.id
                .pop_contact_detail_share);
        mBmivMove.setOnClickListener(this);
        pop_contact_detail_share.setOnClickListener(this);

        contentView.measure(0, 0);
        int width = contentView.getMeasuredWidth();
        int height = contentView.getMeasuredHeight();


        mPopupWindow = new PopupWindow(contentView, width, height);


        int screenWidth = getWindowManager().getDefaultDisplay().getWidth();
        int diffX = screenWidth - width - 10;


        mPopupWindow.setFocusable(true);
        mPopupWindow.setOutsideTouchable(true);
        mPopupWindow.setBackgroundDrawable(new ColorDrawable());


        mPopupWindow.showAsDropDown(mRlTitle, diffX, 4);
弹出Dialog
 mPopupWindow.dismiss();
        if (!mPopupWindow.isShowing()) {
            dialog = new CustomBottomDialog(TempContactDetailActivity.this, R
                    .layout.popup_brand_share, button_id);
            dialog.show();
            //        dialog.dismiss();
            dialog.setButtonOnClickListener(new CustomBottomDialog.ButtonOnClickListener() {
                @Override
                public void buttonOnClick(View v) {

                    switch (v.getId()) {
                        //微信朋友圈分享
                        case R.id.share_friends_btn:
                            Toast.makeText(getApplicationContext(), "微信朋友圈分享", Toast
                                    .LENGTH_LONG).show();
                            break;
                        //微信分享
                        case R.id.share_wechat_btn:
                            Toast.makeText(getApplicationContext(), "微信分享", Toast
                                    .LENGTH_LONG).show();
                            break;
                        //qq分享
                        case R.id.share_qq_btn:
                            Toast.makeText(getApplicationContext(), "qq分享", Toast
                                    .LENGTH_LONG).show();
                            break;
                        //qq空间分享
                        case R.id.share_qq_space_btn:
                            Toast.makeText(getApplicationContext(), "qq空间分享", Toast
                                    .LENGTH_LONG).show();
                            break;
                        //短信分享
                        case R.id.share_message_btn:
                            Toast.makeText(getApplicationContext(), "短信分享", Toast
                                    .LENGTH_LONG).show();
                            break;
                        case R.id.cancelBtn:
                            dialog.dismiss();
                            break;
                    }

                }
            });
        }
Dialog的代码
public class CustomDialog extends Dialog {

    private IsShowListener mIsShowListener;
    private TextView tv_dialog_edit_sex_cancel;
    private int resID;

    public CustomDialog(Context context, @LayoutRes int resId) {
        super(context, R.style.EditSexDialogStyle);
        this.resID = resId;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(resID);

        WindowManager.LayoutParams params = getWindow().getAttributes();
        WindowManager manager = getWindow().getWindowManager();
        Display display = manager.getDefaultDisplay();
        params.gravity = Gravity.BOTTOM;
        params.width = display.getWidth();
        getWindow().setAttributes(params);
        initView();
        initEvent();
    }

    private void initView() {
        tv_dialog_edit_sex_cancel = (TextView) findViewById(R.id.tv_dialog_edit_sex_cancel);
    }

    private void initEvent() {
        tv_dialog_edit_sex_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
    }

    @Override
    public void show() {
        super.show();
        if (mIsShowListener != null) {
            mIsShowListener.isShow(true);
        }
    }

    @Override
    protected void onStop() {
        super.onStop();
        if (mIsShowListener != null) {
            mIsShowListener.isShow(false);
        }
    }

    public void setIsShowLinster(IsShowListener listener) {
        mIsShowListener = listener;
    }

    public interface IsShowListener {
        void isShow(boolean isShow);
    }
}
睡精灵 2016-06-08
  • 打赏
  • 举报
回复
贴代码别人才能帮你分析啊,没代码怎么知道哪里有问题?

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧