Java Code Examples for android.support.v4.content.LocalBroadcastManager#unregisterReceiver()
The following examples show how to use
android.support.v4.content.LocalBroadcastManager#unregisterReceiver() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LocationServiceProxyTest.java From background-geolocation-android with Apache License 2.0 | 6 votes |
@Test(timeout = 5000) public void testStop() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); BroadcastReceiver serviceBroadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { Bundle bundle = intent.getExtras(); int action = bundle.getInt("action"); if (action == LocationServiceImpl.MSG_ON_SERVICE_STOPPED) { latch.countDown(); } } }; LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(InstrumentationRegistry.getTargetContext()); lbm.registerReceiver(serviceBroadcastReceiver, new IntentFilter(LocationServiceImpl.ACTION_BROADCAST)); proxy.start(); proxy.stop(); latch.await(); lbm.unregisterReceiver(serviceBroadcastReceiver); }
Example 2
Source File: LocationServiceProxyTest.java From background-geolocation-android with Apache License 2.0 | 6 votes |
@Test(timeout = 5000) public void testStart() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); BroadcastReceiver serviceBroadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { Bundle bundle = intent.getExtras(); int action = bundle.getInt("action"); if (action == LocationServiceImpl.MSG_ON_SERVICE_STARTED) { latch.countDown(); } } }; LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(InstrumentationRegistry.getTargetContext()); lbm.registerReceiver(serviceBroadcastReceiver, new IntentFilter(LocationServiceImpl.ACTION_BROADCAST)); proxy.start(); latch.await(); lbm.unregisterReceiver(serviceBroadcastReceiver); }
Example 3
Source File: LikeView.java From kognitivo with Apache License 2.0 | 6 votes |
private void tearDownObjectAssociations() { if (broadcastReceiver != null) { LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(getContext()); localBroadcastManager.unregisterReceiver(broadcastReceiver); broadcastReceiver = null; } // If we were already waiting on a controller to be given back, make sure we aren't waiting // anymore. Otherwise when that controller is given back to the callback, it will go and // register a broadcast receiver for it. if (creationCallback != null) { creationCallback.cancel(); creationCallback = null; } likeActionController = null; }
Example 4
Source File: FolioActivity.java From ankihelper with GNU General Public License v3.0 | 6 votes |
@Override protected void onDestroy() { super.onDestroy(); if (outState != null) outState.putParcelable(BUNDLE_READ_POSITION_CONFIG_CHANGE, lastReadPosition); LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(this); localBroadcastManager.unregisterReceiver(searchReceiver); localBroadcastManager.unregisterReceiver(closeBroadcastReceiver); if (r2StreamerServer != null) { r2StreamerServer.stop(); } if (isFinishing()) localBroadcastManager.sendBroadcast(new Intent(FolioReader.ACTION_FOLIOREADER_CLOSED)); }
Example 5
Source File: MyProfileFragment.java From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void onPause() { LocalBroadcastManager manager = LocalBroadcastManager.getInstance(getActivity()); manager.unregisterReceiver(mOnProfileInfoUploadListener); manager.unregisterReceiver(mOnProfileInfoUpdateListener); super.onPause(); }
Example 6
Source File: AppEventsLoggerTests.java From FacebookImageShareIntent with MIT License | 5 votes |
public void testSimpleCall() throws InterruptedException { AppEventsLogger.setFlushBehavior(AppEventsLogger.FlushBehavior.EXPLICIT_ONLY); TestSession session1 = TestSession.createSessionWithSharedUser(getActivity(), null); TestSession session2 = TestSession.createSessionWithSharedUser(getActivity(), null, SECOND_TEST_USER_TAG); AppEventsLogger logger1 = AppEventsLogger.newLogger(getActivity(), session1); AppEventsLogger logger2 = AppEventsLogger.newLogger(getActivity(), session2); final WaitForBroadcastReceiver waitForBroadcastReceiver = new WaitForBroadcastReceiver(); waitForBroadcastReceiver.incrementExpectCount(); final LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(getActivity()); // Need to get notifications on another thread so we can wait for them. runOnBlockerThread(new Runnable() { @Override public void run() { broadcastManager.registerReceiver(waitForBroadcastReceiver, new IntentFilter(AppEventsLogger.ACTION_APP_EVENTS_FLUSHED)); } }, true); logger1.logEvent("an_event"); logger2.logEvent("another_event"); logger1.flush(); waitForBroadcastReceiver.waitForExpectedCalls(); closeBlockerAndAssertSuccess(); broadcastManager.unregisterReceiver(waitForBroadcastReceiver); }
Example 7
Source File: PopUpActivity.java From microbit with Apache License 2.0 | 5 votes |
@Override protected void onDestroy() { super.onDestroy(); Log.d("PopUpActivity", "onDestroy()"); LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(this); localBroadcastManager.sendBroadcast(new Intent(INTENT_ACTION_DESTROYED)); localBroadcastManager.unregisterReceiver(broadcastReceiver); releaseViews(); }
Example 8
Source File: TwilioVoicePlugin.java From cordova-plugin-twiliovoicesdk with MIT License | 5 votes |
@Override public void onDestroy() { //lifecycle events SoundPoolManager.getInstance(cordova.getActivity()).release(); LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(cordova.getActivity()); lbm.unregisterReceiver(mBroadcastReceiver); super.onDestroy(); }
Example 9
Source File: BulkReadCardsDialogFragment.java From Walrus with GNU General Public License v3.0 | 5 votes |
@Override public void onPause() { super.onPause(); LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance( getActivity()); localBroadcastManager.unregisterReceiver(serviceUpdateBroadcastReceiver); localBroadcastManager.unregisterReceiver(runnerUpdateBroadcastReceiver); getActivity().unbindService(bulkReadCardsServiceConnection); }
Example 10
Source File: MyActivity.java From Wrox-ProfessionalAndroid-4E with Apache License 2.0 | 5 votes |
@Override public void onPause() { super.onPause(); // Unregister the receiver LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this); lbm.unregisterReceiver(receiver); }
Example 11
Source File: SKActivity.java From SensingKit-Android with GNU Lesser General Public License v3.0 | 4 votes |
private void unregisterLocalBroadcastManager() { LocalBroadcastManager manager = LocalBroadcastManager.getInstance(mApplicationContext); manager.unregisterReceiver(mBroadcastReceiver); }
Example 12
Source File: ProjectActivity.java From microbit with Apache License 2.0 | 4 votes |
@Override protected void onDestroy() { handler.removeCallbacks(tryToConnectAgain); MBApp application = MBApp.getApp(); LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(application); localBroadcastManager.unregisterReceiver(gattForceClosedReceiver); localBroadcastManager.unregisterReceiver(connectionChangedReceiver); if(dfuResultReceiver != null) { localBroadcastManager.unregisterReceiver(dfuResultReceiver); } application.stopService(new Intent(application, DfuService.class)); super.onDestroy(); releaseViews(); }
Example 13
Source File: BoltsMeasurementEventListener.java From Abelana-Android with Apache License 2.0 | 4 votes |
private void close() { LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(applicationContext); broadcastManager.unregisterReceiver(this); }
Example 14
Source File: FolioReader.java From ankihelper with GNU General Public License v3.0 | 4 votes |
private void unregisterListeners() { LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(context); localBroadcastManager.unregisterReceiver(highlightReceiver); localBroadcastManager.unregisterReceiver(readPositionReceiver); localBroadcastManager.unregisterReceiver(closedReceiver); }
Example 15
Source File: BoltsMeasurementEventListener.java From kognitivo with Apache License 2.0 | 4 votes |
private void close() { LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(applicationContext); broadcastManager.unregisterReceiver(this); }
Example 16
Source File: AppEventsLoggerTests.java From FacebookImageShareIntent with MIT License | 4 votes |
public void testPersistedEvents() throws IOException, ClassNotFoundException { AppEventsLogger.setFlushBehavior(AppEventsLogger.FlushBehavior.EXPLICIT_ONLY); final WaitForBroadcastReceiver waitForBroadcastReceiver = new WaitForBroadcastReceiver(); final LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(getActivity()); // Need to get notifications on another thread so we can wait for them. runOnBlockerThread(new Runnable() { @Override public void run() { broadcastManager.registerReceiver(waitForBroadcastReceiver, new IntentFilter(AppEventsLogger.ACTION_APP_EVENTS_FLUSHED)); } }, true); getActivity().getFileStreamPath(AppEventsLogger.PersistedEvents.PERSISTED_EVENTS_FILENAME).delete(); TestSession session1 = TestSession.createSessionWithSharedUser(getActivity(), null); AppEventsLogger logger1 = AppEventsLogger.newLogger(getActivity(), session1); logger1.logEvent("an_event"); AppEventsLogger.onContextStop(); FileInputStream fis = getActivity().openFileInput(AppEventsLogger.PersistedEvents.PERSISTED_EVENTS_FILENAME); assertNotNull(fis); ObjectInputStream ois = new ObjectInputStream(fis); Object obj = ois.readObject(); ois.close(); assertTrue(obj instanceof HashMap); logger1.flush(); logger1.logEvent("another_event"); waitForBroadcastReceiver.incrementExpectCount(); logger1.flush(); waitForBroadcastReceiver.waitForExpectedCalls(); List<Intent> receivedIntents = waitForBroadcastReceiver.getReceivedIntents(); assertEquals(1, receivedIntents.size()); Intent intent = receivedIntents.get(0); assertNotNull(intent); assertEquals(2, intent.getIntExtra(AppEventsLogger.APP_EVENTS_EXTRA_NUM_EVENTS_FLUSHED, 0)); broadcastManager.unregisterReceiver(waitForBroadcastReceiver); }
Example 17
Source File: BoltsMeasurementEventListener.java From facebook-api-android-maven with Apache License 2.0 | 4 votes |
private void close() { LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(applicationContext); broadcastManager.unregisterReceiver(this); }
Example 18
Source File: SessionTests.java From FacebookImageShareIntent with MIT License | 4 votes |
@SmallTest @MediumTest @LargeTest public void testSetActiveSession() { Session.setActiveSession(null); final WaitForBroadcastReceiver receiverOpened = new WaitForBroadcastReceiver(); final WaitForBroadcastReceiver receiverClosed = new WaitForBroadcastReceiver(); final WaitForBroadcastReceiver receiverSet = new WaitForBroadcastReceiver(); final WaitForBroadcastReceiver receiverUnset = new WaitForBroadcastReceiver(); final LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(getActivity()); try { Runnable initializeOnBlockerThread = new Runnable() { @Override public void run() { broadcastManager.registerReceiver(receiverOpened, getActiveSessionFilter(Session.ACTION_ACTIVE_SESSION_OPENED)); broadcastManager.registerReceiver(receiverClosed, getActiveSessionFilter(Session.ACTION_ACTIVE_SESSION_CLOSED)); broadcastManager.registerReceiver(receiverSet, getActiveSessionFilter(Session.ACTION_ACTIVE_SESSION_SET)); broadcastManager.registerReceiver(receiverUnset, getActiveSessionFilter(Session.ACTION_ACTIVE_SESSION_UNSET)); } }; runOnBlockerThread(initializeOnBlockerThread, true); // null -> null should not fire events assertEquals(null, Session.getActiveSession()); Session.setActiveSession(null); assertEquals(null, Session.getActiveSession()); Session session0 = new Session.Builder(getActivity()). setApplicationId("FakeAppId"). setTokenCachingStrategy(new MockTokenCachingStrategy()). build(); assertEquals(SessionState.CREATED_TOKEN_LOADED, session0.getState()); // For unopened session, we should only see the Set event. receiverSet.incrementExpectCount(); Session.setActiveSession(session0); assertEquals(session0, Session.getActiveSession()); receiverSet.waitForExpectedCalls(); // When we open it, then we should see the Opened event. receiverOpened.incrementExpectCount(); session0.openForRead(null); receiverOpened.waitForExpectedCalls(); // Setting to itself should not fire events Session.setActiveSession(session0); assertEquals(session0, Session.getActiveSession()); // Setting from one opened session to another should deliver a full // cycle of events WaitForBroadcastReceiver.incrementExpectCounts(receiverClosed, receiverUnset, receiverSet, receiverOpened); Session session1 = new Session.Builder(getActivity()). setApplicationId("FakeAppId"). setTokenCachingStrategy(new MockTokenCachingStrategy()). build(); assertEquals(SessionState.CREATED_TOKEN_LOADED, session1.getState()); session1.openForRead(null); assertEquals(SessionState.OPENED, session1.getState()); Session.setActiveSession(session1); WaitForBroadcastReceiver.waitForExpectedCalls(receiverClosed, receiverUnset, receiverSet, receiverOpened); assertEquals(SessionState.CLOSED, session0.getState()); assertEquals(session1, Session.getActiveSession()); closeBlockerAndAssertSuccess(); } finally { broadcastManager.unregisterReceiver(receiverOpened); broadcastManager.unregisterReceiver(receiverClosed); broadcastManager.unregisterReceiver(receiverSet); broadcastManager.unregisterReceiver(receiverUnset); Session.setActiveSession(null); } }
Example 19
Source File: InstallHistoryService.java From fdroidclient with GNU General Public License v3.0 | 4 votes |
public static void unregister(Context context) { LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(context); localBroadcastManager.unregisterReceiver(broadcastReceiver); broadcastReceiver = null; }
Example 20
Source File: LocationServiceTest.java From background-geolocation-android with Apache License 2.0 | 4 votes |
@Test(timeout = 5000) public void testOnLocationOnStoppedService() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(3); BroadcastReceiver serviceBroadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { Bundle bundle = intent.getExtras(); int action = bundle.getInt("action"); if (action == LocationServiceImpl.MSG_ON_SERVICE_STARTED) { latch.countDown(); mService.stop(); //mService.onDestroy(); } if (action == LocationServiceImpl.MSG_ON_SERVICE_STOPPED) { latch.countDown(); mService.onLocation(new BackgroundLocation()); } if (action == LocationServiceImpl.MSG_ON_LOCATION) { latch.countDown(); } } }; LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(InstrumentationRegistry.getTargetContext()); lbm.registerReceiver(serviceBroadcastReceiver, new IntentFilter(LocationServiceImpl.ACTION_BROADCAST)); Config config = Config.getDefault(); config.setStartForeground(false); MockLocationProvider provider = new MockLocationProvider(); Location location = new Location("gps"); location.setProvider("mock"); location.setElapsedRealtimeNanos(2000000000L); location.setAltitude(100); location.setLatitude(49); location.setLongitude(5); location.setAccuracy(105); location.setSpeed(50); location.setBearing(1); provider.setMockLocations(Arrays.asList(location)); mLocationProviderFactory.setProvider(provider); mService.setLocationProviderFactory(mLocationProviderFactory); mService.configure(config); mService.start(); latch.await(); lbm.unregisterReceiver(serviceBroadcastReceiver); }