Robert Strauch
Robert Strauch

Reputation: 12896

Return list item from search dialog to calling activity

My application shall work the following way:

  1. Activity #1 contains a text field (EditText) and a button.
  2. If the user clicks the button a search dialog is opened via onSearchRequested().
  3. This calls the searchable activity #2 which extends ListActivity. It provides a list of items via setListAdapter().
  4. If the user clicks on a list item activity #2 shall pass the selected item's text back to activity #1 and display it in the text field.

Bullets #1-3 are clear and working. However I don't have any idea how to implement #4. I know about the possibility to use intents but it doesn't work if I use an intent after onSearchRequested().

Thanks,
Robert

Upvotes: 1

Views: 1731

Answers (3)

ccheneson
ccheneson

Reputation: 49410

I would simply send an intent with your selected item as extra (putExtra) to your activity#1 (since the search dialog is between activity#1 and activity#2, you can not use startActivityForResult to post back the result to activity#1)

If the search dialog is in activity#1, then you can use startActivityOnResult (thanks dmon)

Upvotes: 1

Cephron
Cephron

Reputation: 1577

Simple, quick fix: store the data statically and do a check to retrieve it in Activity #1's onResume().

Upvotes: 0

Related Questions