This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Android and the fly likes Fetching contacts from phone book Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Mobile » Android
Bookmark "Fetching contacts from phone book" Watch "Fetching contacts from phone book" New topic

Fetching contacts from phone book

Astha Sharma
Ranch Hand

Joined: Oct 15, 2011
Posts: 245

I want to write a code which allows user to click a button, display the list of people's phone numbers, allowing the user to browse through them and pick one and return it to the parent activity, then display selected contact name and number in a Toast. But not getting how to access the returned contact in parent activity. need help.

Thanks in advance

Astha - OCPJP 6 (90%)
Mohan Prasath
Ranch Hand

Joined: Jul 25, 2011
Posts: 38

I have studied about this in a book. You can follow the steps below.

1. Start your child activity through startActivityForResult method.
2. also use the setResult method. (If you are using an IDE to develop android application. You can find the syntax of the method there. PS :- It has two types of implementation)
3. For fetching the returned result use onActivityResult method

For Example, refer the following notepad example Notepad Example

With regards,
Mohan Prasath
Astha Sharma
Ranch Hand

Joined: Oct 15, 2011
Posts: 245

Thanks Mohan Prasad,
I know these steps but not getting how to implement onActivityResult() method. I'm using implicit intent. So i cant call nethod setResult() inside activity displaying phone book.
I agree. Here's the link:
subject: Fetching contacts from phone book
Similar Threads
Screen changing
ActivityNotFoundException while using implicit intent
interface and constructor
Problem with creating a simple Menu in Browser view.
Why error in this code