onActivityResult() not being called in activity

不打扰是莪最后的温柔 提交于 2019-11-29 17:26:39

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
        }
    }
}

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.

You should override onActivityResult in the calling Activity not in TransactionFormActivity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!