Code example for WeakReference

Methods: get

0
        @Override 
        public void onReceive(Context context, Intent intent) {
            // Post a runnable to avoid blocking the broadcast. 
            final boolean timezoneChanged =
                    intent.getAction().equals(Intent.ACTION_TIMEZONE_CHANGED);
            final ClockView clock = mClock.get();
            if (clock != null) {
                clock.mHandler.post(new Runnable() {
                    public void run() { 
                        if (timezoneChanged) {
                            clock.mCalendar = Calendar.getInstance();
                        } 
                        clock.updateTime();
                    } 
                }); 
            } else { 
                try { 
                    mContext.unregisterReceiver(this);
                } catch (RuntimeException e) {
                    // Shouldn't happen 
                }