I'm developing an Android+Firebase app but since I'm new to both techlogies I'm having a problem regarding async calls and I haven't found the solution yet so hope you can help me.
I have the following snippet in my Activity's onCreate
method:
final ArrayList<AssetLocation> assetsLocations = new ArrayList<>();
DatabaseReference assetsLocationReference = database.getReference(FirebaseReferences.ASSETSLOCATION_REFERENCE);
assetsLocationReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
ArrayList<String> assetsLocationSpinner = new ArrayList<String>();
// Create an ArrayAdapter using the string array and a default spinner layout
for (DataSnapshot postSnapshot : snapshot.getChildren()) {
//Getting the data from snapshot
AssetLocation assetsLocation = postSnapshot.getValue(AssetLocation.class);
assetsLocations.add(AssetLocation);
}
}
@Override
public void onCancelled(DatabaseError firebaseError) {
System.out.println("The read failed: " + firebaseError.getMessage());
}
});
I also have a pretty similar call but instead of getting Locations, I'm getting Types.
After this code (inside the onCreate method as well), I'm calling setScreenInfo
which is a function to fill both spinners (and do more stuff) with said data but since it is an async call, the spinners are blank when I execute it.
How can I execute setScreenInfo
once the calls are made? I tried with .once()/.on()
but it's not being recognised by Android Studio as a function.
Thanks for your help!