Skip to content

Day 2.6 - (Bonus) Feeding your Friend's Pets

(Challenge) Feeding other user's pets

You are challenged to add a functionality to feed other people's pets! (p.s. submit this to GTC for a higher chance to win a mechanical keyboard!)

Here are some hints that I will give you:

  1. You will probably need to add a Sign Out button to switch users, for your convenience. The code to sign out of FirebaseAuth looks something like that (finish() is used to make sure our VirtualPetsActivity is closed)

    signOutButton.setOnClickListener(view -> {
        AuthUI.getInstance()
                .signOut(this)
                .addOnCompleteListener(new OnCompleteListener<Void>() {
                    public void onComplete(@NonNull Task<Void> task) {
                        Intent intent = new Intent(MyPetActivity.this, MainActivity.class);
                        startActivity(intent);
                        finish();
                    }
                });
    });
    
  2. You need an EditText to let the user key in their details. Read the documentation to find out how to use EditText and get the value contained within it.

  3. You may want to store user's data by their Email instead in the realtime Database. Realtime Database doesn't allow for . in the key. So we can use a "hack" instead, replacing . with ,. (recall that you need to replace this code in both MainAcitivty and MyPetActivity)

    String userEmail = FirebaseAuth.getInstance().getCurrentUser().getEmail().replace(".", ",");
    
  4. You need a visit button, which should probably launch a new MyPetActivity.java and finish() the current one. You may want to change the way you getting the email for MyPetActivity.java. Perhaps you should store this email in SharedPreferences, after MainActivity, and also after the visit button is pressed, and the email retrieved in MyPetActivity should come from this SharedPreferences.

  5. Better yet, display the email of the person you are currently visiting in a TextView