简体   繁体   English

屏幕超时后将应用程序重定向到主屏幕

[英]Redirect the application to Home screen after screen timeout

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.我只是希望应用程序在屏幕时间用完后立即重定向到其主屏幕......或在用户停止访问后 1 分钟。 Thanks谢谢

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.用户访问时将计数器设置为零。

You can use Handler or CountDownTimer for counting the time or schedule the next task.您可以使用HandlerCountDownTimer来计算时间或安排下一个任务。 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.如果主屏幕就在当前屏幕之前,只需调用 finish() 或 context.finish() 来移动主屏幕。
  • If the Home screen is not just before the current screen use intent to reach the Home screen.如果主屏幕不在当前屏幕之前,请使用意图到达主屏幕。

Hope it will helpful.希望它会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM