Code example for Handler: Scheduling a delayed task

Methods: postDelayedremoveCallbacks

0
 
    /* 
     * Internal implementation 
     */ 
    private void cleanupTimeConfig() { 
        mReconnectHandler.removeCallbacks(mReconnectRunnable);
        mNoInterfaceHandler.removeCallbacks(mNoInterfaceRunnable);
        if (null != mCTConfig) {
            mCTConfig.release();
            mCTConfig = null;
        } 
    } 
 
    private void connectToTimeConfig() { 
        // Get access to the common time service configuration interface.  If we catch a remote 
        // exception in the process (service crashed or no running for w/e reason), schedule an 
        // attempt to reconnect in the future. 
        cleanupTimeConfig(); 
        try { 
            synchronized (mLock) {
                mCTConfig = new CommonTimeConfig();
                mCTConfig.setServerDiedListener(mCTServerDiedListener);
                mCurIface = mCTConfig.getInterfaceBinding();
                mCTConfig.setAutoDisable(AUTO_DISABLE);
                mCTConfig.setMasterElectionPriority(mEffectivePrio);
            } 
 
            if (NO_INTERFACE_TIMEOUT >= 0)
                mNoInterfaceHandler.postDelayed(mNoInterfaceRunnable, NO_INTERFACE_TIMEOUT);
 
            reevaluateServiceState(); 
        } 
        catch (RemoteException e) {
            scheduleTimeConfigReconnect(); 
        } 
    } 
 
    private void scheduleTimeConfigReconnect() { 
        cleanupTimeConfig(); 
        Log.w(TAG, String.format("Native service died, will reconnect in %d mSec",
                                 NATIVE_SERVICE_RECONNECT_TIMEOUT));
        mReconnectHandler.postDelayed(mReconnectRunnable,
                                      NATIVE_SERVICE_RECONNECT_TIMEOUT);
    } 
 
    private void handleNoInterfaceTimeout() { 
        if (null != mCTConfig) {
Stop searching for code, let great code find you!  Add Codota to your java IDE