I have 2 activities: first activity whith Button, which calls The second activity (Open File Dialog) by intent. How to return filename from the second activity to first? By intents ? Which way is worth using ? It`s requiredd to use api <=15.
Asked
Active
Viewed 210 times
-2
-
2http://www.javatpoint.com/android-startactivityforresult-example – Héctor Aug 21 '14 at 11:17
-
You can use intent.. – ngrashia Aug 21 '14 at 11:18
1 Answers
2
Refer this answer here:
To start another activity, only to get a response from the activity as in your case, you can use: startActivityForResult(Intent intent, int identifier_value);
. In your second activity, you can choose to return a result or cancel the result.
Docs states:
The startActivity(Intent) method is used to start a new activity, which will be placed
at the top of the activity stack. It takes a single argument, an Intent, which describes
the activity to be executed.
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.
When an activity exits, it can call setResult(int) to return data back to its parent.
It must always supply a result code, which can be the standard results RESULT_CANCELED,
RESULT_OK, or any custom values starting at RESULT_FIRST_USER. In addition, it can
optionally return back an Intent containing any additional data it wants. All of this
information appears back on the parent's Activity.onActivityResult(), along with the
integer identifier it originally supplied.

ngrashia
- 9,869
- 5
- 43
- 58
-
StartActivityForResult requires api >= 16. I have to support api 15 too. – user2033775 Aug 21 '14 at 12:25
-