質問

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