Checks if idle Time amount of minutes has passed since last network disconnection. - Android java.util

Android examples for java.util:Minute

Description

Checks if idle Time amount of minutes has passed since last network disconnection.

Demo Code


//package com.java2s;

import java.util.Calendar;

public class Main {
    /**//from  ww w.  j  av  a2  s.c  o  m
     * Checks if idleTime amount of minutes has passed since last network disconnection.
     * @param idleTime              Number of minutes to check if they passed since last DC.
     * @param lastDisconnected      Last time disconnected timestamp in milliseconds.
     * @return                      Has idle time passed?
     */
    public static Boolean hasIdleTimePassed(Integer idleTime,
            Long lastDisconnected) {
        if (lastDisconnected.equals(null))
            return true;

        Calendar timeIdle = Calendar.getInstance();
        timeIdle.add(Calendar.MINUTE, -1 * idleTime);

        Calendar timeDisconnected = Calendar.getInstance();
        timeDisconnected.setTimeInMillis(lastDisconnected);

        return timeDisconnected.before(timeIdle);
    }
}

Related Tutorials