PopupWindow出现时CountDownTimer停止

问题描述 投票:0回答:1

在Android活动中,我使用CountDownTimer如下:

    timer = new CountDownTimer(time, 1000) {
        public void onTick(long millisUntilFinished) {
            timeView.setText(String.format(Locale.getDefault(), "%ds", millisUntilFinished / 1000));

            if (millisUntilFinished <= 10000) {
                // Blinking text
                ViewUtil.setBlinking(timeView,Animation.INFINITE);
            } else {
                timeView.clearAnimation();
            }
        }

        public void onFinish() {
            timeView.clearAnimation();
            timeView.setText("0s");
    }.start();

这个计时器只需几秒钟即可倒计时。在同一个活动中,我还使用PopupWindow类显示一个弹出窗口,如下所示:

    LayoutInflater inflater = (LayoutInflater) getApplicationContext().getSystemService(LAYOUT_INFLATER_SERVICE);
        ConstraintLayout mRelativeLayout = (ConstraintLayout) findViewById(R.id.task_layout);
        View customView = inflater.inflate(R.layout.popup_window,mRelativeLayout,false);
        mPopupWindow = new PopupWindow(
                customView,
                LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT
        );
        mPopupWindow.setElevation(5.0f);
        mPopupWindow.showAtLocation(mRelativeLayout, Gravity.CENTER,0,0);

问题是,只要弹出窗口出现,CountDownTimer就会以某种方式停止。我想要的是,当弹出窗口出现并且背景视图仍然更新时,CountDownTimer也会运行。

如何才能做到这一点?

android popupwindow countdowntimer android-popupwindow
1个回答
1
投票

你正在UI线程中运行CountDownTimer,当你弹出窗口线程进入该窗口时,但是我通过PopupWindow文档搜索但它有弱文档找不到多少

在背景中使用CountDownTimer解决它。使用AsynctaskServiceRunnable

© www.soinside.com 2019 - 2024. All rights reserved.