在上一个活动的MainActivity中未调用onActivityResult [英] onActivityResult NOT called in MainActivity from previous Activity

查看:189
本文介绍了在上一个活动的MainActivity中未调用onActivityResult的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这是一个基本问题,我在stackoverflow中看到了关于它的多个答案,但我似乎仍然停滞不前. onActivityResult只是不被调用.

I know this is a basic question and I have seen multiple answers on it in stackoverflow but I seem to be stuck still. The onActivityResult is just not being called.

这是我的代码:

1>在MainActivity中,我具有onActivityResult

1> In MainActivity I have onActivityResult

public class MainActivity extends AppCompatActivity
        implements MasterListFragment.OnImageClickListener {

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        Log.v(LOG_TAG, "Entering onActivityResult");

    }
}

2>在我的第二项活动中,我有这个

2> In my second activity I have this

@Override
    public void onBackPressed() {

        Intent data = new Intent();
        data.putExtra("myData1", "Data 1 value");
        data.putExtra("myData2", "Data 2 value");
        setResult(Activity.RESULT_OK, data);
        finish();
    }

我做一个Log,但Log语句未显示在LOGCAT中

I do a Log and the Log statement is not displayed in the LOGCAT

推荐答案

要在OnActivityResult中返回结果,应使用startActivityForResult(Intent,REQ_CODE)方法开始第二个活动.

For getting result back in OnActivityResult you should use startActivityForResult(Intent,REQ_CODE) method for starting your second activity.

这篇关于在上一个活动的MainActivity中未调用onActivityResult的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆