Code example for Handler

Methods: sendEmptyMessageDelayed

0
    private synchronized void releaseCamera() { 
        Assert(mUsers == 0);
        Assert(mCameraDevice != null);
        long now = System.currentTimeMillis();
        if (now < mKeepBeforeTime) {
            mHandler.sendEmptyMessageDelayed(RELEASE_CAMERA,
                    mKeepBeforeTime - now);
            return; 
        } 
        mCameraDevice.release();
        mCameraDevice = null;
        // We must set this to null because it has a reference to Camera. 
        // Camera has references to the listeners. 
        mParameters = null;
        mCameraId = -1;
    } 
 
    public synchronized void keep() { 
        // We allow (mUsers == 0) for the convenience of the calling activity. 
        // The activity may not have a chance to call open() before the user 
        // choose the menu item to switch to another activity.