SUNITHA  SUNITHA - 1 year ago 98
Android Question

how to create two onactivityresult for two different class

I am having two different classes. One class is for adding image and uploading it to server and another class for editing the saved image with new image. So for getting image from sdcard, in add class I am using

. Same thing I am trying to use in edit class because in this class im having an
where new image is added but it is not allowing me to create
in edit class. Saying error as onactivityresult is already defined. If someone knows please help me.


protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null) {
Uri filePath = data.getData();
try {
//Getting the Bitmap from Gallery
bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), filePath);
//Setting the Bitmap to ImageView
} catch (IOException e) {

Answer Source

Use it like this:

startActivityForResult (intent, int requestCode);

Then in onActivityResult you can use switch case using requestCode. Like:

public void onActivityResult(int requestCode, int resultCode, Intent data)
     switch(requestCode) {
           //Have your cases here
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download