-1

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.

Hua
  • 1
  • 1
    You have to add it. Um, if you really need to ask this question I'm not sure if you really understand what a function is, how they work, and how inheritance works. You really should learn standard Java programming before diving into Android. – Gabe Sechan Apr 07 '15 at 00:56

4 Answers4

1

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.

Community
  • 1
  • 1
codeMagic
  • 44,549
  • 13
  • 77
  • 93
1

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

codeMagic
  • 44,549
  • 13
  • 77
  • 93
0

If you don't see it there, simply add it to your class.

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
...
}
posit labs
  • 8,951
  • 4
  • 36
  • 66
0

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.

Ifan Iqbal
  • 3,053
  • 5
  • 28
  • 31