Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android onActivityResult() doesn't get called

I've got a problem I don't know how to solve. This is my code of the MainActivity.java which starts a new activity:

Intent intent = new Intent(this, AssociationActivity.class);
    intent.putExtra("data", json);
    startActivityForResult(intent, 0);

Additionaly, I have the following onActivityResult()-method:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    System.out.print("works outside!");
    if (requestCode == 1) {
        if(resultCode == RESULT_OK){
            System.out.print("works inside!");
        }
        if (resultCode == RESULT_CANCELED) {

        }
    }
}

And this is where the result should be sent to the MainActivity:

Intent returnIntent = new Intent();
returnIntent.putExtra("result", string);
setResult(RESULT_OK, returnIntent);
finish();

It seems that the onActivityResult() doesn't even get called as I don't have any output on the console.

In the AndroidManifest.xml I neither use the singleIntent nor the noHistory parameter.

Any suggestions why it doesn't work?

like image 947
fgroeger Avatar asked Sep 15 '26 12:09

fgroeger


1 Answers

requestCode change from 1 to 0. as shown below

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    System.out.print("works outside!");
    if (requestCode == 0) {
        if(resultCode == RESULT_OK){
            System.out.print("works inside!");
        }
        if (resultCode == RESULT_CANCELED) {

        }
    }
}
like image 106
Krishna V Avatar answered Sep 18 '26 03:09

Krishna V



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!