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:
-
You will probably need to add a
Sign Outbutton to switch users, for your convenience. The code to sign out of FirebaseAuth looks something like that (finish()is used to make sure ourVirtualPetsActivityis 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(); } }); }); -
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.
-
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 bothMainAcitivtyandMyPetActivity)String userEmail = FirebaseAuth.getInstance().getCurrentUser().getEmail().replace(".", ","); -
You need a visit button, which should probably launch a new
MyPetActivity.javaandfinish()the current one. You may want to change the way you getting the email forMyPetActivity.java. Perhaps you should store this email inSharedPreferences, afterMainActivity, and also after the visit button is pressed, and the email retrieved inMyPetActivityshould come from thisSharedPreferences. - Better yet, display the email of the person you are currently visiting in a
TextView