-1

I'm looking for a best way to implement the following:

  • I have a main Activity that started when the application launched. One of the items in this Activity is the TextView called "Other Manufacturer".
  • When a user selects this TextView the OnClickListener launches another Activity allowing the user to search my database for an available Manufacturer.
  • Once the user selects a Manufacturer, the application should return the user back to the main Activity with the appropriate Manufacturer displayed in the TextView.

I got everything working, but I'm stuck on how to pass the selected Manufacturer back to the Main Activity and fill in the TextView. I've searched everywhere, but found mostly examples of how to pass value from one activity to a new activity.

What I need is how pass a value from an activity to a previous open activity and write the value into a TextView.

Should I use Fragment?

If you could share with me an example or point me to some examples, I would greatly appreciate it.

Thank you in advance for your help.

Sam
  • 86,580
  • 20
  • 181
  • 179
user2105000
  • 125
  • 1
  • 3
  • 8
  • 1
    There are many ways to do this, please read [How do I pass data between activities in Android?](http://stackoverflow.com/q/2091465/1267661) – Sam Apr 04 '13 at 16:21

2 Answers2

1

What I need is how pass a value from an activity to a previous open activity and write the value into a TextView.

You need to make two general changes to do this:

  1. In the main Activity, override onActivityResult() and start the second Activity with startActivityForResult().
  2. In the second Activity, call setResult() after the user selects a manufacturer.

Brief explanation:

  • startActivityForResult() starts an Activity but tells the current activity to expect some type of result.
  • setResult() passes the results from the child Activity back to it's parent.
  • onActivityResult() receives the result.

This tutorial has code examples and a more detailed explanation.


Having written all of that, you might be able to use an AutoCompleteTextView and link this to your database rather than using a separate Activity.

Sam
  • 86,580
  • 20
  • 181
  • 179
0

You can use either a Bundle an Intent or the SharedPreferences Bundle and Intent has the getString and putString method that will allow you to store and retrive the String instance you need.

Blackbelt
  • 156,034
  • 29
  • 297
  • 305