I am a beginner of android programming, but I can not find onActivityResult function in my activity class. there are only onCreate, onCreateOptionsMenu,and onOptionsItemsSelected functions in my activity file. So my question is where I can find onActivityResult function. thank you guys.
4 Answers
You can find it by adding it
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// your code
}
It won't be added automagically because you don't need it unless you start the next Activity
with startActivityForResult()
. Then it is called by calling setResult()
in the Activity
started with startActivtyForResult()
.
See the docs for more information
This answer I gave should also give you a good idea of how and why to use it.
You need to override it! If you're using android studio...
Right click-generate-override- and select onActivityResult
In eclipse, you need to code it manually

- 44,549
- 13
- 77
- 93

- 390
- 2
- 13
If you don't see it there, simply add it to your class.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
...
}

- 8,951
- 4
- 36
- 66
In Android Studio, you can create it automatically without typing the code with shortcut Ctrl+O
to generate any override method. That shortcut will bring you a pop up window where you can search the override method you need.

- 3,053
- 5
- 28
- 31