目标:对于App在后台注销用户,因此当用户选择HOME按钮退出应用程序时。计数器将启动并注销用户。非常感谢
问题:无法运行
public void IdleLogout(){
Timer timer = new Timer();
@Override
protected @ onPause() {
super.onPause();
//Timer starts count when Home Button is selected
int seconds = 60;
timer.schedule(new StartCounting(), 60*1000);
}
}
class StartCounting extends TimerTask{
@Override
public void run() {
// TODO Auto-generated method stub
Intent intent_login= new Intent(context, RootActivity.class);
//CLOSE ALL OTHER ACTIVITIES AND BRING THE ACTIVITY BEING LAUNCHED TO THE TOP
intent_login.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent_login);
}
}
答案 0 :(得分:0)
ScheduledExecutorService scheduler;
@override
onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.your_activity_nocticeboard);
scheduler = Executors.newSingleThreadScheduledExecutor();
IdleLogout();// if you want to run it at activity statrt up
}
public void IdleLogout(){
scheduler.scheduleAtFixedRate(new Runnable() {
public void run() {
Intent intent_login= new Intent(context, RootActivity.class);
intent_login.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent_login);
}
}, 0, 60*10000, TimeUnit.SECONDS);
}