你们应利用AlarmManager或时事服务,在每3-5秒中执行。
I have also make a function of using alarm manager auto logout if user ideal for 5 min then it is logout.
public static void autoLogOut(Context context) {
MyAlarmService.mContext = context;
Intent myIntent = new Intent(context, MyAlarmService.class);
pendingIntent = PendingIntent.getService(context, 0, myIntent, 0);
AlarmManager alarmManager = (AlarmManager) context
.getSystemService("alarm");
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.add(Calendar.SECOND, (5 * 60));
alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
pendingIntent);
// Toast.makeText(context, "Start Alarm", Toast.LENGTH_LONG).show();
}
如果用户对5分钟有理想,则在使用后执行。