0

I'd like to start another activity when a value is added in the database of Firebase.

No error is appearing but when I add a value in the database nothing happens.

Here's my sample code. I've been searching for the past days but it is my first app and I'm a bit confused.

DatabaseReference databaseReference;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_blackscreen);
        databaseReference = FirebaseDatabase.getInstance().getReference();
    }

    @Override
    protected void onStart() {
        super.onStart();
        usingFirebaseDatabase();
    }

    public void usingFirebaseDatabase() {
        databaseReference.child("uploads")
                .addListenerForSingleValueEvent(new ValueEventListener() {
                    @Override
                    public void onDataChange(DataSnapshot dataSnapshot) {
                        do {
                        if (dataSnapshot.exists()) {
                            Intent intent = new Intent(blackscreen.this,MainActivity.class);
                            startActivity(intent);
                        } else  {
                            return;
                        }

                    } while (!dataSnapshot.exists());
                    }

                    @Override
                    public void onCancelled(DatabaseError databaseError) {
                        Toast.makeText(blackscreen.this, "NO images found \n" + databaseError.getMessage(), Toast.LENGTH_SHORT).show();
                    }
                });
        }
    }
Frank van Puffelen
  • 418,229
  • 62
  • 649
  • 645
Alex
  • 3
  • 1
  • You are starting an activity but didn't pass the data to it. Follow this link to learn how to do that. https://stackoverflow.com/questions/2091465/how-do-i-pass-data-between-activities-in-android-application – Prince Ali Dec 11 '20 at 23:19
  • 1
    Thank you it's working now! – Alex Dec 12 '20 at 22:24

0 Answers0