---
title: "Getting a Result from an Activity"  
description: "Hi Everyone, I am here to explain how to get the result from an other activity in one activity"  
author: "Anonymous User"  
published: 2014-11-17  
updated: 2026-05-13  
canonical: https://www.mindstick.com/articles/1533/getting-a-result-from-an-activity  
category: "android"  
tags: ["android", "android activity", "android intent"]  
reading_time: 4 minutes  

---

# Getting a Result from an Activity

Previously we see how to communicate between two activities in Android( Interacting one app to other app in android ). Here we see how to get result from an Android activity\

Sometimes starting an activity doesn’t have to be one-way, i.e. we can start another activity and receives result back. To receive a result, call startActivityForResult() (instead of startActivity()). For e.g. our app can start a camera and receive the captured photo as a results.

Of course, the activity that responds must be designed to return a result. When it does, it sends the result as another onActivityResult() [callback](https://www.mindstick.com/articles/152/using-the-callback).

Start the Activity

We need to pass an additional integer argument to the startActivityForResult() method.The integer argument is a “request code” that identifies the request. When we receive the result Intent, the callback provides the same request code so that the app can properly identify the result and determine how to handle it.

For Example, here’s how to start an activity that allow a user to pick a contact:

Static final int PICK_CONTACT_REQUEST = 1; // The request code\
……\
Private void pickContact() {\
Intnet pickContactIntent = new Intent( Intnet.ACTION_PICK, Uri.parse(“content : //contacts”));\
startActivityForResult(pickContactIntent, PICK_CONTACT_REQUEST);\
}

|  |
| --- |

Receive the Result

When the user is done with the subsequent activity and returns, the [system calls](https://www.mindstick.com/interview/12746/the-last-callback-in-the-lifecycle-of-an-activity-is-ondestroy-the-system-calls-this-method-on-your-activity-as-the-final-signal-that-your-activity-instance-is-being-completely-removed-from-the-sys) our activity’s onActivityResult() method. This method incudes three [arguments](https://answers.mindstick.com/qa/92535/what-are-the-different-types-of-arguments):

· The request code we pass to startActivityFortResult()

· A request code specified by the second activity. This is either RESULT_OK if the [operation](https://yourviews.mindstick.com/view/83916/why-is-it-necessary-to-sterilize-operation-theater) was successful or RESULT_CANCELED if the user backed out or the operation failed for the some reason.

· An Intent that carries the result data.

For e.g. here’s how we can [handle the result](https://www.mindstick.com/forum/159913/how-to-handle-the-result-of-a-resolved-promise) for the “pick a contact” intent:

@Override\
protected void onActivityResult( int requestCode, int resultCode, Intent data) {\
//Check which request we’re responding to\
If(requestcode == RESULT_OK) {\
// Make sure the request we successful\
If(resultCode == RESULT_OK) {\
// The user picked a contact.\
// The Intent’s data Uri identifies which contact was selected.\
// Do something with the contact here (bigger example below)\
}\
}

\

|  |
| --- |

The result Intent returned by android’s Contacts or people app provides a content Uri that identifies the contact the user selected.

Read the contact Data

Here’s the code that shows how to query the result data to get the phone number from the the selected contact:

@Override\
Protected void onActivityResult(int requestCode, int resultCode, Intent data) {\
// check which request it is that we’re responding to\
If(requestCode == PICK_CONTACT_REQUEST) {\
// Make sure the request was successful\
If(resultcode == RESULT_OK) {\
// Get theURI that points to the selected contact\
Uri ContactUri = data.getData();\
// We only need the NUMBER column, because there will be only one row in the result\
String[] projection = {Phone.NUMBER};\
// Perform the query on the contact to get the NUMBER column\
// We don't need a selection or sort order (there's only [one result](https://answers.mindstick.com/qa/42846/what-was-one-result-of-the-haymarket-riot) for the given URI)\
// CAUTION: The query() method should be called from a separate thread to avoid blocking\
// your app's UI thread. (For simplicity of the sample, this code doesn't do that.)\
// Consider using CursorLoader to perform the query.\
Cursor cursor = getContnetREsolver().query(contentUri, projection, nul, null, null);\
Cursor.moveToFirst();\
// Retrieve the phone number from the NUMBER column\
Int column = cursor.getColumnbIndex(Phone.NUMBER);\
// Do something with the phone number..\
}\
}\
}

This post is referred from [Google docs](https://www.mindstick.com/blog/246065/office-365-vs-google-docs-features-comparison) Getting a Result from an Activity

In my next post, we will see the ways to save the data in Android - [Saving data in Android: Saving in Key-Value Sets](https://www.mindstick.com/blog/703/saving-data-in-android-saving-in-key-value-sets)

---

Original Source: https://www.mindstick.com/articles/1533/getting-a-result-from-an-activity

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
