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
Asked
Active
Viewed 364 times
-1
-
use new Handler().postDelay(new Runnable(),delaytime) – D.J Oct 03 '16 at 09:41
-
Thanks for replying but..i don't want application to be redirect after exact 1 minute.. i want application to redirect after some time after user stop accessing it.. just like screen timeout in android – Nishant Sambyal Oct 03 '16 at 09:46
-
use Thread for it. – D.J Oct 03 '16 at 09:49
-
can you provide the required code for it.? – Nishant Sambyal Oct 03 '16 at 09:49
-
I have post my answer code.Please tell me it is working or not. – D.J Oct 03 '16 at 10:05
2 Answers
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.
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