public NetworkChangeNotifierAutoDetect(Observer observer, Context context) { mObserver = observer; mContext = context.getApplicationContext(); mConnectivityManagerDelegate = new ConnectivityManagerDelegate(context); mConnectionType = getCurrentConnectionType(); ActivityStatus.registerStateListener(this); }
@SmallTest @Feature({"Sync"}) public void testEnsureConstructorRegistersListener() throws Exception { final AtomicBoolean listenerCallbackCalled = new AtomicBoolean(); // Create instance. new InvalidationController(mContext) { @Override public void onActivityStateChange(int newState) { listenerCallbackCalled.set(true); } }; // Ensure initial state is correct. assertFalse(listenerCallbackCalled.get()); // Ensure we get a callback, which means we have registered for them. ActivityStatus.onStateChange(new Activity(), ActivityStatus.RESUMED); assertTrue(listenerCallbackCalled.get()); }
/** Creates an instance using {@code context} to send intents. */ @VisibleForTesting InvalidationController(Context context) { mContext = Preconditions.checkNotNull(context.getApplicationContext()); ActivityStatus.registerStateListener(this); }