-1

I am creating an application with possible high security in it. i simply want an application to redirect to its home screen as soon as the screen time runs out.. or after 1 minute when users stop accessing. Thanks

2 Answers2

1
int counter=0;

boolean isStart=true;

private void start(){

Thread t=new Thread(new Runnable() {

@Override
public void run() {

    while (isStart){

        try {

            Thread.sleep(100);

            counter++;

            if(counter>=10){//for one minute

                //your code

                isStart=false;

            }

        } catch (InterruptedException e) {

            e.printStackTrace();

        }

    }

}

});

t.start();

}

set counter zero when user access.

Soham
  • 4,397
  • 11
  • 43
  • 71
D.J
  • 1,439
  • 1
  • 12
  • 23
0

You can use Handler or CountDownTimer for counting the time or schedule the next task. After the time finish you need to redirect to home screen.

  • If the Home screen is just before the current screen simply call finish() or context.finish() to move the Home screen.
  • If the Home screen is not just before the current screen use intent to reach the Home screen.

Hope it will helpful.

D_Alpha
  • 4,039
  • 22
  • 36