I have 1 Activity and 1 fragment which have the following code
Activity 1
Database createConn(Database database) {
try {
Manager manager = new Manager(new AndroidContext(context), Manager.DEFAULT_OPTIONS);
database = manager.getDatabase("couchbaseevents");
} catch (Exception e) {
android.util.Log.d(TAG, "Error getting database", e);
return database;
}
return database;
}
private com.couchbase.lite.View createView(Database database){
com.couchbase.lite.View calendarView = database.getView("calendar");
calendarView.setMap(new Mapper() {
@Override
public void map(Map<String, Object> document, Emitter emitter) {
{
emitter.emit(document.get("date"),document.get("cost"));
}
}
},"2");
return calendarView;
}
Database database = createConn(database);
calendarView = createView(database);
Fragment 1
Database createConn(Database database) {
try {
Manager manager = new Manager(new AndroidContext(context), Manager.DEFAULT_OPTIONS);
database = manager.getDatabase("couchbaseevents");
} catch (Exception e) {
android.util.Log.d(TAG, "Error getting database", e);
return database;
}
return database;
}
Database database = createConn(database);
Query query = database.getView("calendar").createQuery();
When I run the query on CBL in fragment I get empty result but if I create View
in fragment and not in activity I get desired result, But I dont want like that. I want that view should be created in activity and called in fragment. Is this possible? if yes then please give example.