Join Albert Lo for an in-depth discussion in this video Handle results of Google account, part of Android Development: Modern Android UI Design Elements.
- [Instructor] Now let's switch back to Google photos fragment to add in our code to handle activity result. We're going to scroll up again to on view created, and just below on view created, we're going to add our on activity result. It's a fragment life cycle activity so we can add in it's public on activity result. Input parameters on a request code, result code, and the intent.
In our on activity result, we're going to handle the Google account picker's selection here. So we will make another Picasa client library call. First let's call these super class on activity result, passing in our request code, result code, and data. And then next, let's make our Picasa client call on activity result. And then we pass in the same three parameters, a request code, result code, and data.
We're also going to change some calls here. First one is to observe on the main thread. And the next one is to add our subscriber. It's a new completable subscriber. And in our on completed callback, we're going to make a new private method called update account, and also to load our albums.
In the on error callback, we can log an error. We will call the throwable's get message method call. And also print out the stack trace. Now let's implement our update account. I'm going to copy it here, go scroll down just below the method and insert our private method.
We will do two things in update account method. The first is to retrieve our account using another Picasa library call. And if we do have a valid account, then we're going to store it. Let's check whether we have a valid account. We're going to make a call to preference manager here to store our account name.
In order to store our account name, we have to go into edit mode for the preference manager. So let's call edit, then we can call put string. And we pass in the pref account key that we created earlier, and supply our account name. And then we call the apply method to store our account name into shared preferences. One last thing we will do is to complete our private method for handle error.
Scroll down to the bottom for handle error. And we're going to add a couple of things. The first is to print out the stack trace. And the next one is to dismiss the progress animation for refresh layout. And it's an optional step but we'll also make a toast to show a dialogue message to the user that something went wrong.
And we'll call the throwable's get message method and then call the show method call. Okay so now we have finished the work flow for selecting or creating our Google accounts.
- Creating a custom layout with XML
- Setting up OnClick handlers
- Making API calls
- Creating custom views
- Implementing ViewHolder objects
- Signing certificates
- Adding a checkbox