Getting Results from Activities

The next step is to display the photo in your app. To do this, you need to look a little deeper into intents. At this point, you’ve already started a new activity via the startActivity method, but there is also a startActivityForResult method. You can call this method to tell you when an activity has ended and what has happened, and you can use it to pass data between activities. You can pass data to activities that you have created or even to native Android activities such as the camera.

To use the startActivityForResult method, you pass the Intent and an extra parameter of type integer. This is known as the request code. When this new activity finishes, it will return the request code you have sent, along with ...

Get Learning Android™ Application Programming: A Hands-On Guide to Building Android Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.