Code example for IntentFilter

Methods: registerReceiver, addAction

0
    protected void onAttachedToWindow() { 
        super.onAttachedToWindow(); 
 
        if (!mAttached) {
            mAttached = true;
            IntentFilter filter = new IntentFilter();
 
            filter.addAction(Intent.ACTION_TIME_TICK);
            filter.addAction(Intent.ACTION_TIME_CHANGED);
            filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
 
            getContext().registerReceiver(mIntentReceiver, filter, null, mHandler);
        } 
 
        // NOTE: It's safe to do these after registering the receiver since the receiver always runs 
        // in the main thread, therefore the receiver can't run before this method returns. 
 
        // The time zone may have changed while the receiver wasn't registered, so update the Time 
        mCalendar = new Time();
 
        // Make sure we update to the current time