Send data backwards to a previous activity

I would like some help in sending data backwards to an Activity that is already running.

I want the user to be able to select an option from a list and then that selection be used in a previous activity. I know how to do it going forward using intents but can’t see how that would work in this case without having an arbitrary number of the same activity windows running at the same time.

  • What is the primary usage of upstream messaging in GCM Cloud Connection Server?
  • Getting position in onCreateViewHolder
  • Is it possible to generate a 'share on Facebook' link that opens the native Facebook App on Android/iOS/mobile instead of the web share dialog?
  • What is the difference between SOAP 1.1, SOAP 1.2, HTTP GET & HTTP POST methods for Android?
  • Application loading the wrong textures on opening again
  • Why does removeOnGlobalLayoutListener throw a NoSuchMethodError?
  • Sort of like changing the settings within the phone but more having access to a string. If you need any more information just ask.

    Related posts:

    How to set a radio button in Android
    Controlling view visibility from a resources
    Restrict Autocomplete search to a particular country in Google Places Android API
    How can I add my application's shortcut to the homescreen upon app installation?
    How to send a Intent with telegram
    List activity with header, footer and empty all visible
  • Eclipse Juno won't create Android Activity
  • ActionBar up navigation recreates parent activity instead of onResume
  • Android ListView not refreshing after notifyDataSetChanged
  • Why does popbackstack call onCreateView of the fragment?
  • How make android edittext hint center and left cursor
  • SoapFault - faultcode: '1062' faultstring: 'Shipping method is not available'
  • 4 Solutions collect form web for “Send data backwards to a previous activity”

    There are two ways to do this, the first is rather than calling startActivity(), call startActivityForResult(), this is what the documentation has to say about it:

    Sometimes you want to get a result back from an activity when it ends. For example, you may start an activity that lets the user pick a person in a list of contacts; when it ends, it returns the person that was selected. To do this, you call the startActivityForResult(Intent, int) version with a second integer parameter identifying the call. The result will come back through your onActivityResult(int, int, Intent) method.

    The other way to do it is to send out a broadcast at the end of your activity, and register a broadcastReceiver() in your original activity.

    If you start the second activity using startActivityForResult() rather than startActivity, then when the second activity completes you can set a resultCode and an Intent. It will then call the method:

    protected void onActivityResult(int requestCode, int resultCode, Intent intent) {

    in your first Activity, where you can read the resultCode and the Intent data

    You need to use startActivityForResult.

    Take a look at Activity#startActivityForResult() and Activity#setResult() methods

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.