AlarmManager Calling Function in Same Class

Posted by jsc123 on Stack Overflow See other posts from Stack Overflow or by jsc123
Published on 2013-07-01T16:04:20Z Indexed on 2013/07/01 16:21 UTC
Read the original article Hit count: 195

I am trying to give a LocationClient a two-minute period to connect before calling getLastLocation on it. Initially I implemented this with a Timer (and TimerTask), but because Timers do not work in sleepmode, I would like to translate it to an AlarmManager. However, I am a bit confused as to how to do this, considering an AlarmManager calls another class, whereas I want to remain in the same class and simply delay for a two-minute period.

This is how it looks with a Timer.

 Timer theTimer = new Timer();
    theTimer.schedule(new TimerTask() {
        @Override
        public void run() {
            if(checkIfGooglePlay() && checkTime()) {
                getPostLocation();
                stopSelf();
                mLocationClient.disconnect();
            }
        }
    }, TWO_MINUTES);

© Stack Overflow or respective owner

Related posts about android

Related posts about timer