Widgets + Firebase Database

Viewed 1163

An overview: I'm trying to create a homescreen widget for Android that takes assignments and displays them in a list.

The problem: Querying the database takes longer than the program takes to call getCount().

The code:

public class WidgetViewFactory implements RemoteViewsService.RemoteViewsFactory {
...
    @Override
    public void onCreate() {
        Database.dueAssignmentDb.addListenerForSingleValueEvent(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                for (DataSnapshot userSnapshot : dataSnapshot.getChildren()) {
                    Assignment assignment = userSnapshot.getValue(Assignment.class);
                    assignments.add(assignment);
                }
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {

            }
        });
    }

...

    @Override
    public int getCount() {
        Log.d("Widget", "getCount: " + assignments.size());
        return assignments.size();
    }

...

tl;dr expecting getCount() to return anything other then 0, returns 0.

0 Answers
Related