onActivityResult() not being called in activity

后端 未结 3 1789
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-22 08:44

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;

TransactionFo

相关标签:
3条回答
  • 2020-12-22 09:07

    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.

    0 讨论(0)
  • 2020-12-22 09:08

    You should override onActivityResult in the calling Activity not in TransactionFormActivity

    0 讨论(0)
  • 2020-12-22 09:13

    You are doing it a little wrong..

    In your FirstActivity you should call:

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

    In your SecondActivity you should call:

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

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

    protected void onActivityResult(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
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题