Skip to content Skip to sidebar Skip to footer

Onactivityresult() Not Being Called In Activity

I have looked at several examples and I cant find what I am doing wrong. my onActivityResult() method is not being called on my activity; TransactionFormActivity is starting up a n

Solution 1:

You are doing it a little wrong..

In your FirstActivity you should call:

//your code...
Intent i = newIntent(this, SecondActivity.class);
startActivityForResult(i, 1);

In your SecondActivity you should call:

IntentreturnIntent=newIntent();
returnIntent.putExtra("result",result);
setResult(RESULT_OK,returnIntent);
finish();

and then back in your FirstActivity you use the onActivityResult to get the data back

protectedvoidonActivityResult(int requestCode, int resultCode, Intent data){

    if (requestCode == 1) {
        if(resultCode == RESULT_OK){
            String result=data.getStringExtra("result");
        }
        if (resultCode == RESULT_CANCELED) {
            //Write your code if there's no result
        }
    }
}

Solution 2:

As i don't have reputation to comment, so just want to make sure you don't have

android:launchMode="singleInstance"

in manifest or equivalent argument to create a intent.

Solution 3:

You should override onActivityResult in the calling Activity not in TransactionFormActivity

Post a Comment for "Onactivityresult() Not Being Called In Activity"