문제

I have an android app it displays web view.I want know the app idle time because If session expires i want go to my android login activity how can i do it. Please provide any suggestions for me.

Thanks in advance

도움이 되었습니까?

해결책

You can start chronometer inside pause method and once activity resumed you can get the duration through chronometer. for code reference :

// create a instance for chronometer
Chronometer duration = new Chronometer(this);

// starts chronometer inside pause override method
duration.setBase(0);
duration.start();

// you also need to add onTick listener.
duration.setOnChronometerTickListener(new OnChronometerTickListener(){
        @Override
        public void onChronometerTick(Chronometer arg0) {
            NumberFormat formatter = new DecimalFormat("00");
            long countUp = (SystemClock.elapsedRealtime() - arg0.getBase()) / 1000;
            String asText = formatter.format(countUp / 60) + ":" + formatter.format(countUp % 60);
        if (is_pause == false) {
            duration_time = asText;
        } 

// once done stop the chronometer inside stop override method and set a flag, check      this falg inside OnTickListener and get the duration asText.
duration.stop();
is_pause = false;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top