本文整理汇总了Java中com.google.firebase.database.DatabaseReference.keepSynced方法的典型用法代码示例。如果您正苦于以下问题:Java DatabaseReference.keepSynced方法的具体用法?Java DatabaseReference.keepSynced怎么用?Java DatabaseReference.keepSynced使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.firebase.database.DatabaseReference
的用法示例。
在下文中一共展示了DatabaseReference.keepSynced方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testMultipleKeepSynced
import com.google.firebase.database.DatabaseReference; //导入方法依赖的package包/类
@Test
public void testMultipleKeepSynced() throws Exception {
DatabaseReference ref = IntegrationTestUtils.getRandomNode(masterApp);
try {
ref.keepSynced(true);
ref.keepSynced(true);
ref.keepSynced(true);
assertIsKeptSynced(ref);
// If it were balanced, this would not be enough
ref.keepSynced(false);
ref.keepSynced(false);
assertNotKeptSynced(ref);
// If it were balanced, this would not be enough
ref.keepSynced(true);
assertIsKeptSynced(ref);
} finally {
// cleanup
ref.keepSynced(false);
}
}
示例2: testRemoveSingleListener
import com.google.firebase.database.DatabaseReference; //导入方法依赖的package包/类
@Test
public void testRemoveSingleListener() throws Exception {
DatabaseReference ref = IntegrationTestUtils.getRandomNode(masterApp);
ref.keepSynced(true);
try {
assertIsKeptSynced(ref);
// This will add and remove a listener.
new ReadFuture(
ref,
new ReadFuture.CompletionCondition() {
@Override
public boolean isComplete(List<EventRecord> events) {
return true;
}
})
.timedGet();
assertIsKeptSynced(ref);
} finally {
// cleanup
ref.keepSynced(false);
}
}
示例3: testKeepSyncedWithExistingListener
import com.google.firebase.database.DatabaseReference; //导入方法依赖的package包/类
@Test
public void testKeepSyncedWithExistingListener() throws Exception {
DatabaseReference ref = IntegrationTestUtils.getRandomNode(masterApp);
ReadFuture readFuture;
ref.keepSynced(true);
try {
assertIsKeptSynced(ref);
readFuture =
new ReadFuture(ref, new ReadFuture.CompletionCondition() {
@Override
public boolean isComplete(List<EventRecord> events) {
return events.get(events.size() - 1).getSnapshot().getValue().equals("done");
}
});
} finally {
// cleanup
ref.keepSynced(false);
}
// Should trigger our listener.
ref.setValueAsync("done");
readFuture.timedGet();
}
示例4: addItem
import com.google.firebase.database.DatabaseReference; //导入方法依赖的package包/类
private void addItem(HashMap<String, String> images, final Hotel item) {
DatabaseReference itemsRef = FirebaseDatabase.getInstance().getReferenceFromUrl(Constants.FIREBASE_URL_ITEMS);
itemsRef.keepSynced(true);
item.setImagesUrls(images);
itemsRef = itemsRef.push().getRef();
itemsRef.setValue(item, new DatabaseReference.CompletionListener() {
@Override
public void onComplete(DatabaseError databaseError, DatabaseReference databaseReference) {
mUploadProgressDialog.dismiss();
if (databaseError == null) {
Toast.makeText(AddActivity.this, "Item uploaded Successfully.", Toast.LENGTH_SHORT).show();
startActivity(new Intent(AddActivity.this, MainActivity.class)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
} else {
Toast.makeText(AddActivity.this, "unable to add.", Toast.LENGTH_SHORT).show();
}
}
});
}
示例5: testKeepSynced
import com.google.firebase.database.DatabaseReference; //导入方法依赖的package包/类
@Test
public void testKeepSynced() throws Exception {
DatabaseReference ref = IntegrationTestUtils.getRandomNode(masterApp);
ref.keepSynced(true);
assertIsKeptSynced(ref);
ref.keepSynced(false);
assertNotKeptSynced(ref);
}
示例6: testKeepSyncedAffectOnQueries
import com.google.firebase.database.DatabaseReference; //导入方法依赖的package包/类
@Test
public void testKeepSyncedAffectOnQueries() throws Exception {
DatabaseReference ref = IntegrationTestUtils.getRandomNode(masterApp);
ref.keepSynced(true);
Query query = ref.limitToFirst(5);
query.keepSynced(true);
assertIsKeptSynced(ref);
ref.keepSynced(false);
assertNotKeptSynced(ref);
// currently, setting false on the default query affects all queries at that location
assertNotKeptSynced(query);
}
示例7: testKeptSyncedChild
import com.google.firebase.database.DatabaseReference; //导入方法依赖的package包/类
@Test
public void testKeptSyncedChild() throws Exception {
DatabaseReference ref = IntegrationTestUtils.getRandomNode(masterApp);
DatabaseReference child = ref.child("random-child");
ref.keepSynced(true);
try {
assertIsKeptSynced(child);
} finally {
// cleanup
ref.keepSynced(false);
}
}
示例8: testKeptSyncedRoot
import com.google.firebase.database.DatabaseReference; //导入方法依赖的package包/类
@Test
public void testKeptSyncedRoot() throws Exception {
DatabaseReference ref = FirebaseDatabase.getInstance().getReference();
ref.keepSynced(true);
try {
assertIsKeptSynced(ref);
} finally {
// cleanup
ref.keepSynced(false);
}
}
示例9: provideDatabaseReference
import com.google.firebase.database.DatabaseReference; //导入方法依赖的package包/类
@Singleton
@Provides
DatabaseReference provideDatabaseReference(Context context, FirebaseDatabase firebaseDatabase) {
DatabaseReference fontsRef = firebaseDatabase.getReference(
context.getString(R.string.fonts));
fontsRef.keepSynced(BuildConfig.DEBUG); //force sync on debug
return firebaseDatabase.getReference(context.getString(R.string.fonts));
}