开发者

Counter not getting resumed when an activity is resumed

I have a counter in my activity A and on finish of it, I have to perform some actions. The problem is the counter is getting reset when I move onto another activity and then come back to this activity A, which shouldn't happen. Why is it so?

My Counter class is:

private class Counter extends CountDownTimer {

        public Counter(long millisInFuture, long countDownInterval) {
            super(millisInFuture, countDownInterval);
        }

        public void onFinish() {
            //perform some actions
        }

        public void onTick(long millisUntilFinished) {
            int mi开发者_StackOverflow社区nute = (int) (millisUntilFinished / (1000 * 60));
            int sec = (int) ((millisUntilFinished - (minute * 60 * 1000)) / 1000);
            minuteText.setText("" + minute);
            secondText.setText("" + sec);
            }
        }
    }

I call my counter in onCreate() as:

new Counter(countdowntime * 60 * 1000), 1000).start();

How to solve this issue? Please reply. Thanks in advance.


You should probably start your counter in onResume instead of in onCreate and pause the counter in onPause (or you could finish the counter if isFinishing() returns true in onPause).


I got it worked...The problem was i was using activity stack...while calling an intent we should give an id for it so that it uniquely identifies each intent. When I gave that, it got worked.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜