August 5, 2018 comments 93 Reads

In part 4 of the FirebaseUI Firestore tutorial, we will add another activity to our app, from which the user can add a new document to the Firestore database.
The activity will contain 2 EditText fields and a NumberPicker, from which we get the input values, create a new Note object, and add it to our Firestore collection.
We override onCreateOptionsMenu to add our save button as a menu item and handle clicks on it in onOptionsItemSelected.
To add an up button to the action bar, we add the parentActivityName attribute to the MainActivity tag in the AndroidManifest.xml file, and by setting launchMode to “singleTop” we avoid restarting this activity when we navigate back. To change the up arrow into a close (x) icon, we call setHomeAsUpIndicator on getSupportActionBar and pass a vector drawable. With setTitle we change the title of the activity.
Watch the Cloud Firestore tutorial first: