當前位置: 首頁>>代碼示例>>Java>>正文


Java DatabaseReference.removeEventListener方法代碼示例

本文整理匯總了Java中com.google.firebase.database.DatabaseReference.removeEventListener方法的典型用法代碼示例。如果您正苦於以下問題:Java DatabaseReference.removeEventListener方法的具體用法?Java DatabaseReference.removeEventListener怎麽用?Java DatabaseReference.removeEventListener使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.firebase.database.DatabaseReference的用法示例。


在下文中一共展示了DatabaseReference.removeEventListener方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testSubscribeThenUnsubscribeWithoutProblems

import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
@Test
public void testSubscribeThenUnsubscribeWithoutProblems()
    throws InterruptedException {
  DatabaseReference ref = IntegrationTestUtils.getRandomNode(masterApp) ;

  ValueEventListener listener =
      new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot snapshot) {}

        @Override
        public void onCancelled(DatabaseError error) {
          fail("Should not be cancelled");
        }
      };

  ValueEventListener listenerHandle = ref.addValueEventListener(listener);
  ZombieVerifier.verifyRepoZombies(ref);
  ref.removeEventListener(listenerHandle);
  ZombieVerifier.verifyRepoZombies(ref);
  ValueEventListener listenerHandle2 = ref.addValueEventListener(listener);
  ZombieVerifier.verifyRepoZombies(ref);
  ref.removeEventListener(listenerHandle2);
  ZombieVerifier.verifyRepoZombies(ref);
}
 
開發者ID:firebase,項目名稱:firebase-admin-java,代碼行數:26,代碼來源:EventTestIT.java

示例2: testSubscribeThenUnsubscribeWithoutProblemsWithLimit

import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
@Test
public void testSubscribeThenUnsubscribeWithoutProblemsWithLimit()
    throws InterruptedException {
  DatabaseReference ref = IntegrationTestUtils.getRandomNode(masterApp) ;

  ValueEventListener listener =
      new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot snapshot) {}

        @Override
        public void onCancelled(DatabaseError error) {
          fail("Should not be cancelled");
        }
      };

  ValueEventListener listenerHandle = ref.limitToLast(100).addValueEventListener(listener);
  ZombieVerifier.verifyRepoZombies(ref);
  ref.removeEventListener(listenerHandle);
  ZombieVerifier.verifyRepoZombies(ref);
  ValueEventListener listenerHandle2 = ref.limitToLast(100).addValueEventListener(listener);
  ZombieVerifier.verifyRepoZombies(ref);
  ref.removeEventListener(listenerHandle2);
  ZombieVerifier.verifyRepoZombies(ref);
}
 
開發者ID:firebase,項目名稱:firebase-admin-java,代碼行數:26,代碼來源:EventTestIT.java

示例3: testUnregisterSameCallbackTooManyTimes

import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
@Test
public void testUnregisterSameCallbackTooManyTimes()
    throws InterruptedException {
  DatabaseReference ref = IntegrationTestUtils.getRandomNode(masterApp) ;

  ValueEventListener listener =
      ref.addValueEventListener(
          new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot snapshot) {
              // no-op
            }

            @Override
            public void onCancelled(DatabaseError error) {
              // no-op
            }
          });

  ZombieVerifier.verifyRepoZombies(ref);

  ref.removeEventListener(listener);
  ref.removeEventListener(listener);
  ZombieVerifier.verifyRepoZombies(ref);
}
 
開發者ID:firebase,項目名稱:firebase-admin-java,代碼行數:26,代碼來源:EventTestIT.java

示例4: getBookFromIdInList

import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
public void getBookFromIdInList(@BOOK_LISTS String currentList, String bookId,
                                final GetBookFromListListener bookListener) {
  final DatabaseReference reference = database.getReference()
      .child(currentUser.getUid())
      .child(currentList)
      .child(bookId);

  final ValueEventListener valueEventListener = new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot dataSnapshot) {
      bookListener.onReceivedBook(dataSnapshot.getValue(Book.class));
      reference.removeEventListener(this);
    }

    @Override
    public void onCancelled(DatabaseError databaseError) {
      bookListener.onError();
      reference.removeEventListener(this);
    }
  };

  reference.addValueEventListener(valueEventListener);

}
 
開發者ID:paulnunezm,項目名稱:Boookito-Capstone-Project,代碼行數:25,代碼來源:FirebaseRepo.java

示例5: closeAllActiveListeners

import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
public void closeAllActiveListeners() {
    for (ValueEventListener listener : activeListeners.keySet()) {
        DatabaseReference reference = activeListeners.get(listener);
        reference.removeEventListener(listener);
    }

    activeListeners.clear();
}
 
開發者ID:rozdoum,項目名稱:social-app-android,代碼行數:9,代碼來源:DatabaseHelper.java

示例6: testQueriesOnLeafNodes

import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
@Test
public void testQueriesOnLeafNodes()
    throws InterruptedException, ExecutionException, TestFailure, TimeoutException {
  DatabaseReference ref = IntegrationTestUtils.getRandomNode(masterApp) ;
  final Semaphore semaphore = new Semaphore(0);
  new WriteFuture(ref, "leaf-node").timedGet();

  final List<DataSnapshot> snapshots = new ArrayList<>();
  Query query = ref.orderByChild("foo").limitToLast(1);
  final ValueEventListener listener =
      query.addValueEventListener(
          new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot snapshot) {
              snapshots.add(snapshot);
              semaphore.release();
            }

            @Override
            public void onCancelled(DatabaseError error) {
              Assert.fail();
            }
          });

  TestHelpers.waitFor(semaphore);

  Assert.assertEquals(1, snapshots.size());
  Assert.assertNull(snapshots.get(0).getValue());

  // cleanup
  TestHelpers.waitForRoundtrip(ref);
  ref.removeEventListener(listener);
}
 
開發者ID:firebase,項目名稱:firebase-admin-java,代碼行數:34,代碼來源:OrderByTestIT.java

示例7: testServerRespectsKeyIndex

import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
@Test
public void testServerRespectsKeyIndex()
    throws InterruptedException, ExecutionException, TimeoutException, TestFailure {
  List<DatabaseReference> refs = IntegrationTestUtils.getRandomNode(masterApp, 2);
  DatabaseReference writer = refs.get(0);
  DatabaseReference reader = refs.get(1);

  Map<String, Object> initial = MapBuilder.of("a", 1, "b", 2, "c", 3);
  // If the server doesn't respect the index, it will send down limited data, but with no
  // offset, so the expected and actual data don't match.
  Query query = reader.orderByKey().startAt("b").limitToFirst(2);

  new WriteFuture(writer, initial).timedGet();

  final List<String> actualChildren = new ArrayList<>();
  final Semaphore semaphore = new Semaphore(0);
  ValueEventListener valueListener =
      query.addValueEventListener(
          new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot snapshot) {
              for (DataSnapshot child : snapshot.getChildren()) {
                actualChildren.add(child.getKey());
              }
              semaphore.release();
            }

            @Override
            public void onCancelled(DatabaseError error) {
              Assert.fail();
            }
          });

  TestHelpers.waitFor(semaphore);
  Assert.assertEquals(ImmutableList.of("b", "c"), actualChildren);

  // cleanup
  reader.removeEventListener(valueListener);
}
 
開發者ID:firebase,項目名稱:firebase-admin-java,代碼行數:40,代碼來源:OrderByTestIT.java

示例8: testRemovingDefaultListener

import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
@Test
public void testRemovingDefaultListener()
    throws InterruptedException, ExecutionException, TimeoutException, TestFailure, IOException {
  DatabaseReference ref = IntegrationTestUtils.getRandomNode(masterApp) ;

  Object initialData = MapBuilder.of("key", "value");
  new WriteFuture(ref, initialData).timedGet();

  ValueEventListener listener =
      ref.orderByKey()
          .addValueEventListener(
              new ValueEventListener() {
                @Override
                public void onDataChange(DataSnapshot snapshot) {}

                @Override
                public void onCancelled(DatabaseError error) {}
              });

  ref.addValueEventListener(listener);
  // Should remove both listener and should remove the listen sent to the server
  ref.removeEventListener(listener);

  // This used to crash because a listener for ref.orderByKey() existed already
  Object result = new ReadFuture(ref.orderByKey()).waitForLastValue();
  assertEquals(initialData, result);
}
 
開發者ID:firebase,項目名稱:firebase-admin-java,代碼行數:28,代碼來源:OrderByTestIT.java

示例9: testRemoveListenerOnDefaultQuery

import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
@Test
public void testRemoveListenerOnDefaultQuery()
    throws InterruptedException, ExecutionException, TimeoutException, TestFailure {
  DatabaseReference ref = IntegrationTestUtils.getRandomNode(masterApp);
  new WriteFuture(ref.child("a"), "foo", 100).timedGet();

  final Semaphore semaphore = new Semaphore(0);
  final DataSnapshot[] snapshotHolder = new DataSnapshot[1];

  ValueEventListener listener = ref.startAt(99).addValueEventListener(new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot snapshot) {
      snapshotHolder[0] = snapshot;
      semaphore.release();
    }

    @Override
    public void onCancelled(DatabaseError error) {
      fail("Unexpected error: " + error);
    }
  });

  TestHelpers.waitFor(semaphore);
  Map<String, Object> expected = MapBuilder.of("a", "foo");
  TestHelpers.assertDeepEquals(expected, snapshotHolder[0].getValue());

  ref.removeEventListener(listener);

  new WriteFuture(ref.child("a"), "bar", 100).timedGet();
  // the listener is removed the value should have not changed
  TestHelpers.assertDeepEquals(expected, snapshotHolder[0].getValue());
}
 
開發者ID:firebase,項目名稱:firebase-admin-java,代碼行數:33,代碼來源:QueryTestIT.java

示例10: breakCombo

import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
/** Remove the saved listener from the saved ref.*/
public void breakCombo(){
    DatabaseReference comboRef = FirebaseDatabase.getInstance().getReferenceFromUrl(ref);

    listener.killEvent();

    if (listener.getType() == FirebaseGeneralEvent.ChildEvent)
    {
        comboRef.removeEventListener((ChildEventListener) listener);
    }
    else if (listener.getType() == FirebaseGeneralEvent.ValueEvent)
    {
        comboRef.removeEventListener((ValueEventListener) listener);
    }
}
 
開發者ID:MobileDev418,項目名稱:AndroidBackendlessChat,代碼行數:16,代碼來源:FirebaseEventCombo.java

示例11: onConnect

import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 */
@Override
public void onConnect(final ConnectedListener listener)
{
    DatabaseReference ref = FirebaseDatabase.getInstance().getReference(".info/connected");
    if (connectionValueListener == null && listener != null) {
        connectionValueListener = new ConnectionValueListener();
        ref.addValueEventListener(connectionValueListener);
    } else if (connectionValueListener != null && listener == null) {
        ref.removeEventListener(connectionValueListener);
        connectionValueListener = null;
    }
    connectedListener = listener;
}
 
開發者ID:mk-5,項目名稱:gdx-fireapp,代碼行數:17,代碼來源:Database.java

示例12: testUseFallbackThenDefineIndex

import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
@Test
public void testUseFallbackThenDefineIndex()
    throws InterruptedException, ExecutionException, TimeoutException, TestFailure, IOException {

  DatabaseReference writer = IntegrationTestUtils.getRandomNode(masterApp) ;
  DatabaseReference readerReference = FirebaseDatabase.getInstance(masterApp).getReference();
  DatabaseReference reader = readerReference.child(writer.getPath().toString());

  Map<String, Object> foo1 =
      TestHelpers.fromJsonString(
          "{ "
              + "\"a\": {\"order\": 2, \"foo\": 1}, "
              + "\"b\": {\"order\": 0}, "
              + "\"c\": {\"order\": 1, \"foo\": false}, "
              + "\"d\": {\"order\": 3, \"foo\": \"hello\"} }");

  new WriteFuture(writer, foo1).timedGet();

  final List<DataSnapshot> snapshots = new ArrayList<>();
  final Semaphore semaphore = new Semaphore(0);
  Query query = reader.orderByChild("order").limitToLast(2);
  final ValueEventListener listener =
      query.addValueEventListener(
          new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot snapshot) {
              snapshots.add(snapshot);
              semaphore.release();
            }

            @Override
            public void onCancelled(DatabaseError error) {
              Assert.fail();
            }
          });

  TestHelpers.waitFor(semaphore);

  Assert.assertEquals(1, snapshots.size());
  Map<String, Object> expected = MapBuilder.of(
      "d", MapBuilder.of("order", 3L, "foo", "hello"),
      "a", MapBuilder.of("order", 2L, "foo", 1L));
  Assert.assertEquals(expected, snapshots.get(0).getValue());

  uploadRules(masterApp, formatRules(reader, "{ \".indexOn\": \"order\" }"));

  Map<String, Object> fooE = TestHelpers.fromJsonString("{\"order\": 1.5, \"foo\": true}");
  new WriteFuture(writer.child("e"), fooE).timedGet();
  TestHelpers.waitForRoundtrip(reader);

  Map<String, Object> fooF =
      TestHelpers.fromJsonString("{\"order\": 4, \"foo\": {\"bar\": \"baz\"}}");
  new WriteFuture(writer.child("f"), fooF).timedGet();
  TestHelpers.waitForRoundtrip(reader);

  TestHelpers.waitFor(semaphore);
  Assert.assertEquals(2, snapshots.size());

  Map<String, Object> expected2 =
      new MapBuilder()
          .put(
              "f",
              new MapBuilder()
                  .put("order", 4L)
                  .put("foo", MapBuilder.of("bar", "baz"))
                  .build())
          .put("d", MapBuilder.of("order", 3L, "foo", "hello"))
          .build();
  Assert.assertEquals(expected2, snapshots.get(1).getValue());

  // cleanup
  TestHelpers.waitForRoundtrip(reader);
  reader.removeEventListener(listener);
}
 
開發者ID:firebase,項目名稱:firebase-admin-java,代碼行數:75,代碼來源:OrderByTestIT.java

示例13: testUpdatesForUnindexedQuery

import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
@Test
public void testUpdatesForUnindexedQuery()
    throws InterruptedException, ExecutionException, TestFailure, TimeoutException {
  List<DatabaseReference> refs = IntegrationTestUtils.getRandomNode(masterApp, 2);
  final DatabaseReference reader = refs.get(0);
  final DatabaseReference writer = refs.get(1);

  final List<DataSnapshot> snapshots = new ArrayList<>();

  Map<String, Object> value = new HashMap<>();
  value.put("one", new MapBuilder().put("index", 1).put("value", "one").build());
  value.put("two", new MapBuilder().put("index", 2).put("value", "two").build());
  value.put("three", new MapBuilder().put("index", 3).put("value", "three").build());

  new WriteFuture(writer, value).timedGet();

  final Semaphore semaphore = new Semaphore(0);

  Query query = reader.orderByChild("index").limitToLast(2);
  final ValueEventListener listener =
      query.addValueEventListener(
          new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot snapshot) {
              snapshots.add(snapshot);
              semaphore.release();
            }

            @Override
            public void onCancelled(DatabaseError error) {
              Assert.fail();
            }
          });

  TestHelpers.waitFor(semaphore);

  Assert.assertEquals(1, snapshots.size());

  Map<String, Object> expected1 = new HashMap<>();
  expected1.put("two", new MapBuilder().put("index", 2L).put("value", "two").build());
  expected1.put("three", new MapBuilder().put("index", 3L).put("value", "three").build());
  Assert.assertEquals(expected1, snapshots.get(0).getValue());

  // update child which should trigger value event
  writer.child("one/index").setValueAsync(4);
  TestHelpers.waitFor(semaphore);

  Assert.assertEquals(2, snapshots.size());
  Map<String, Object> expected2 = new HashMap<>();
  expected2.put("three", new MapBuilder().put("index", 3L).put("value", "three").build());
  expected2.put("one", new MapBuilder().put("index", 4L).put("value", "one").build());
  Assert.assertEquals(expected2, snapshots.get(1).getValue());

  // cleanup
  TestHelpers.waitForRoundtrip(reader);
  reader.removeEventListener(listener);
}
 
開發者ID:firebase,項目名稱:firebase-admin-java,代碼行數:58,代碼來源:OrderByTestIT.java

示例14: testServerRespectsValueIndex

import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
@Test
public void testServerRespectsValueIndex()
    throws InterruptedException, ExecutionException, TimeoutException, TestFailure, IOException {
  List<DatabaseReference> refs = IntegrationTestUtils.getRandomNode(masterApp, 2);
  DatabaseReference writer = refs.get(0);
  DatabaseReference reader = refs.get(1);

  final String indexRule = "{ \".indexOn\": \".value\"}";
  String rules = formatRules(writer, indexRule);

  uploadRules(masterApp, rules);

  Map<String, Object> initial = MapBuilder.of("a", 1, "c", 2, "b", 3);
  // If the server doesn't respect the index, it will send down limited data, but with no
  // offset, so the expected and actual data don't match.
  Query query = reader.orderByValue().startAt(2).limitToFirst(2);

  new WriteFuture(writer, initial).timedGet();

  final List<String> actualChildren = new ArrayList<>();
  final Semaphore semaphore = new Semaphore(0);
  ValueEventListener valueListener =
      query.addValueEventListener(
          new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot snapshot) {
              for (DataSnapshot child : snapshot.getChildren()) {
                actualChildren.add(child.getKey());
              }
              semaphore.release();
            }

            @Override
            public void onCancelled(DatabaseError error) {
              Assert.fail();
            }
          });

  TestHelpers.waitFor(semaphore);

  Assert.assertEquals(ImmutableList.of("c", "b"), actualChildren);

  // cleanup
  reader.removeEventListener(valueListener);
}
 
開發者ID:firebase,項目名稱:firebase-admin-java,代碼行數:46,代碼來源:OrderByTestIT.java

示例15: testUnsubscribeEventsAndConfirmEventsNoLongerFire

import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
@Test
public void testUnsubscribeEventsAndConfirmEventsNoLongerFire()
    throws TestFailure, ExecutionException, TimeoutException,
        InterruptedException {
  DatabaseReference ref = IntegrationTestUtils.getRandomNode(masterApp) ;

  final AtomicInteger callbackCount = new AtomicInteger(0);

  final ValueEventListener listener =
      ref.addValueEventListener(
          new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot snapshot) {
              if (snapshot.getValue() != null) {
                callbackCount.incrementAndGet();
              }
            }

            @Override
            public void onCancelled(DatabaseError error) {
              fail("Should not be cancelled");
            }
          });
  ZombieVerifier.verifyRepoZombies(ref);

  for (int i = 0; i < 3; ++i) {
    ref.setValueAsync(i);
  }

  TestHelpers.waitForRoundtrip(ref);
  ref.removeEventListener(listener);
  ZombieVerifier.verifyRepoZombies(ref);

  for (int i = 10; i < 13; ++i) {
    ref.setValueAsync(i);
  }

  for (int i = 20; i < 22; ++i) {
    ref.setValueAsync(i);
  }
  new WriteFuture(ref, 22).timedGet();
  assertEquals(3, callbackCount.get());
}
 
開發者ID:firebase,項目名稱:firebase-admin-java,代碼行數:44,代碼來源:EventTestIT.java


注:本文中的com.google.firebase.database.DatabaseReference.removeEventListener方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。