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 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 ourVirtualPetsActivity
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(); } }); });
-
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 bothMainAcitivty
andMyPetActivity
)String userEmail = FirebaseAuth.getInstance().getCurrentUser().getEmail().replace(".", ",");
-
You need a visit button, which should probably launch a new
MyPetActivity.java
andfinish()
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 inMyPetActivity
should come from thisSharedPreferences
. - Better yet, display the email of the person you are currently visiting in a
TextView