CountDownTimer在取消呼叫后永远不会停止

时间:2015-12-15 11:36:05

标签: android android-fragments countdowntimer illegalstateexception

我对CountDownTimer对象有奇怪的问题。这意味着我使用CountDownTimer在几秒钟后显示消息。

初始计时器:

    notLoggedInTimer = new CountDownTimer(120000, 1000) {
                    @Override
                    public void onTick(long millisUntilFinished) {
                    }

                    @Override
                    public void onFinish() {
    //393 line                    
notLoggedInSignUpDialog = SignUpDialog.newInstance(getString(R.string.sign_up_dialog_title), new View.OnClickListener() {        
                            @Override
                            public void onClick(View v) {
                                if (!UserDataHelper.getInstance().checkIfLogged(getActivity()))
                                    getActivity().finish();
                            }
                        });
                        notLoggedInSignUpDialog.show(getActivity().getSupportFragmentManager(), SignUpDialog.TAG);

                    }
                };
                notLoggedInTimer.start();

它在onViewCreated片段中初始化。我将使用onDestory()方法cancle()CounterDownTimer对象调用。

在120000(2分钟)之后,我将接受:

> java.lang.IllegalStateException: Fragment
> WatchStreamLiveFragment{2dae83aa} not attached to Activity 12-15
> 12:21:32.613 30378-30378/com.vyda.stream E/AndroidRuntime:     at
> android.support.v4.app.Fragment.getResources(Fragment.java:639) 12-15
> 12:21:32.613 30378-30378/com.vyda.stream E/AndroidRuntime:     at
> android.support.v4.app.Fragment.getString(Fragment.java:661) 12-15
> 12:21:32.613 30378-30378/com.vyda.stream E/AndroidRuntime:     at
> com.vyda.stream.fragments.streaming.WatchStreamLiveFragment$5.onFinish(WatchStreamLiveFragment.java:393)
> 12-15 12:21:32.613 30378-30378/com.vyda.stream E/AndroidRuntime:    
> at android.os.CountDownTimer$1.handleMessage(CountDownTimer.java:127)
> 12-15 12:21:32.613 30378-30378/com.vyda.stream E/AndroidRuntime:    
> at android.os.Handler.dispatchMessage(Handler.java:102) 12-15
> 12:21:32.613 30378-30378/com.vyda.stream E/AndroidRuntime:     at
> android.os.Looper.loop(Looper.java:211) 12-15 12:21:32.613
> 30378-30378/com.vyda.stream E/AndroidRuntime:     at
> android.app.ActivityThread.main(ActivityThread.java:5371) 12-15
> 12:21:32.613 30378-30378/com.vyda.stream E/AndroidRuntime:     at
> java.lang.reflect.Method.invoke(Native Method) 12-15 12:21:32.613
> 30378-30378/com.vyda.stream E/AndroidRuntime:     at
> java.lang.reflect.Method.invoke(Method.java:372) 12-15 12:21:32.613
> 30378-30378/com.vyda.stream E/AndroidRuntime:     at
> com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:945)
> 12-15 12:21:32.613 30378-30378/com.vyda.stream E/AndroidRuntime:    
> at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:740)

0 个答案:

没有答案