how do i get my android app which is connected to a realtime firebase database to create a toast on update in the realtime database?

This is my fireabase databse View Database

All I want is to generate a toast or a notification in my android app saying what changes or which new entry was added under the faces or movements directory. I am trying to use the addValueEventListener() method but I cant get it to work. Below is the onCreate() method in my android app. I am trying to implement this by following this https://www.youtube.com/watch?v=vxCDS6DaFSQ youtube tutorial. I have already connected my app to firebase. Also, I am trying to get this done by not using the firebase cloud function.

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toast.makeText(this, "Firebase Successful", Toast.LENGTH_SHORT).show();

    FirebaseDatabase database = FirebaseDatabase.getInstance();
    DatabaseReference myRef = database.getReference("message");
    myRef.child("App")
            .addValueEventListener(new ValueEventListener() {
                @Override
                public void onDataChange(@NonNull DataSnapshot snapshot) {
                    Iterable<DataSnapshot> children = snapshot.getChildren();

                    for (DataSnapshot child: children)
                    {
                        String value = child.getValue(String.class);
                        Toast.makeText(MainActivity.this, "Data" + value, Toast.LENGTH_SHORT).show();
                    }
                }

                @Override
                public void onCancelled(@NonNull DatabaseError error) {

                }
            });
}

If this cannot be implemented by using the addValueEventListener() method, is there any other comparatively simpler alternative to this?



Read more here: https://stackoverflow.com/questions/64951457/how-do-i-get-my-android-app-which-is-connected-to-a-realtime-firebase-database-t

Content Attribution

This content was originally published by Rohit Dhuri at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: