15分钟后由于Android不活动而自动注销 [英] Auto logout after 15 minutes due to inactivity in android
本文介绍了15分钟后由于Android不活动而自动注销的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
由于用户不活动,如何在15分钟后使用android中的计时器自动注销?
How to use timer in android for auto logout after 15 minutes due to inactivity of user?
我在我的loginActivity.java中使用了下面的代码
I am using bellow code for this in my loginActivity.java
public class BackgroundProcessingService extends Service {
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
timer = new CountDownTimer(5 *60 * 1000, 1000) {
public void onTick(long millisUntilFinished) {
//Some code
//inactivity = true;
timer.start();
Log.v("Timer::", "Started");
}
public void onFinish() {
//Logout
Intent intent = new Intent(LoginActivity.this,HomePageActivity.class);
startActivity(intent);
//inactivity = false;
timer.cancel();
Log.v("Timer::", "Stoped");
}
};
return null;
}
}
然后单击登录按钮
Intent intent1 = new Intent(getApplicationContext(),
AddEditDeleteActivity.class);
startService(intent1);
请咨询......
这种错误消息会在15分钟后显示
This type of error message is shown after 15 mins
推荐答案
使用CountDownTimer
Use CountDownTimer
CountDownTimer timer = new CountDownTimer(15 *60 * 1000, 1000) {
public void onTick(long millisUntilFinished) {
//Some code
}
public void onFinish() {
//Logout
}
};
用户停止任何操作后,使用 timer.start()
,并且用户执行操作时执行 timer.cancel()
When user has stopped any action use timer.start()
and when user does the action do timer.cancel()
这篇关于15分钟后由于Android不活动而自动注销的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文